update fetching php

This commit is contained in:
Odweta
2024-01-07 01:48:38 +00:00
parent 263efd5b65
commit 8181fa15af
12 changed files with 10 additions and 1077 deletions
+1 -2
View File
@@ -1,6 +1,5 @@
{
"require": {
"fabpot/goutte": "^4.0",
"clio/clio": "^0.1.8"
"fabpot/goutte": "^4.0"
}
}
+1 -46
View File
@@ -4,53 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "60aa2585bcce885bae7ab3a59a70ba3f",
"content-hash": "7854cb91fa2eeb20d171a6ed16dc50cf",
"packages": [
{
"name": "clio/clio",
"version": "0.1.8",
"source": {
"type": "git",
"url": "https://github.com/nramenta/clio.git",
"reference": "6a9f600b73fa213e817d5c1e67a4641aecd156ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nramenta/clio/zipball/6a9f600b73fa213e817d5c1e67a4641aecd156ef",
"reference": "6a9f600b73fa213e817d5c1e67a4641aecd156ef",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"type": "library",
"autoload": {
"psr-0": {
"Clio": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nofriandi Ramenta",
"email": "nramenta@gmail.com"
}
],
"description": "Lightweight utility and helper classes for CLI applications",
"keywords": [
"cli",
"console",
"daemon"
],
"support": {
"issues": "https://github.com/nramenta/clio/issues",
"source": "https://github.com/nramenta/clio/tree/0.1.8"
},
"time": "2014-06-22T14:49:41+00:00"
},
{
"name": "fabpot/goutte",
"version": "v4.0.3",
+6 -6
View File
@@ -222,13 +222,13 @@ if (!isset($_POST["username"]) || !isset($_POST["password"])) {
echo create_json_file(get_cal_week(), 0);
}
if ($_POST["cal_tdy_tmr"]) {
echo create_json_file(get_cal_tdy_tmr(), 0);
}
#if ($_POST["cal_tdy_tmr"]) {
# echo create_json_file(get_cal_tdy_tmr(), 0);
#}
if ($_POST["grades"]) {
echo create_json_file(get_grades(), 0);
}
#if ($_POST["grades"]) {
# echo create_json_file(get_grades(), 0);
#}
}
?>
-22
View File
@@ -1,22 +0,0 @@
Copyright (c) 2012 Nofriandi Ramenta
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
-279
View File
@@ -1,279 +0,0 @@
# Clio
Clio is a lightweight utility and helper classes for CLI applications.
It provides colored output, prompts, confirmation inputs, selections, background
processes, as well as a way to start and stop daemons.
## Installation
The prefered way to install Clio is through [composer][Composer]; the minimum
composer.json configuration is:
```
{
"require": {
"clio/clio": "0.1.8"
}
}
```
PHP 5.4 is required. This library is developed on and is meant to be used on
POSIX systems with the posix, pcntl, and sockets extensions loaded.
## Console
The Console class provides helpers for interactive command line input/output.
### Console::stdin($raw = false)
Waits for user input. If `$raw` is set to `true`, returns the input without
right trimming for `PHP_EOL`.
### Console::input($prompt = null, $raw = false)
Asks the user for input which ends when the user types a `PHP_EOL` character.
You can optionally provide a prompt string. If `$raw` is set to `true`, returns
the input without right trimming for `PHP_EOL`.
### Console::stdout($text, $raw = false)
Prints `$text` to STDOUT. The text can contain text color and style specifiers.
This method detects whether the text is to be sent out to TTY or to a file
through the use of shell redirection and acts accordingly, in the case of the
latter, by stripping the text of all color and style specifiers.
If the second parameter is set to true, then it will print `$text` as is with
all text color and style specifiers intact regardless of whether it's printing
to TTY or to a file.
```php
<?php
use Clio\Console;
Console::stdout('Hello, World!');
```
### Console::output($text, $raw = false)
The same as `Console::stdout` except it automatically appends a `PHP_EOL`.
### Console::stderr($text, $raw = false)
Behaves like `Console::stdout` except it's for STDERR.
### Console::error($text, $raw = false)
The same as `Console::stderr` except it automatically appends a `PHP_EOL`.
### Console::prompt($text, $options)
This function prompts the user for input. Several options are available:
- `required`: True if input is necessary, false otherwise.
- `default`: If the user does not provide an input, this is the default value.
- `pattern`: Regular expression pattern to match.
- `validator`: Callable to validate input. Must return `true` or `false`.
- `error`: Default error message.
If an input error occurs, the prompt will repeat and will keep asking the user
for input until it satisfies all the requirements in the `$options` array. Note
that if you supply a `default` option, `required` is not enforced.
```php
<?php
$db_host = Console::prompt('database host', ['default' => 'localhost']);
```
If you provide your own validator callable, you can pass a custom error message
to the second parameter:
```php
<?php
$file = Console::prompt('File', [
'required' => true,
'validator' => function($input, &$error = null) {
if (is_readable($input)) {
return true;
} else {
$error = 'Path given is not a readable file';
return false;
}
}
]);
```
Note that for this to work, the second parameter must be declared a reference.
### Console::confirm($text)
Asks the user for a simple y/n answer. The answer can be `'y'`, `'n'`, `'Y'`, or
`'N'`. Returns either `true` or `false`.
```php
<?php
$sure = Console::confirm('are you sure?');
```
### Console::select($text, $options)
Asks the user to choose from a selection of options. The `$options` array is a
key-value pairs of input and explanation. The `'?'` input option is appended
automatically and it serves as the help option showing all other options along
with their respective explanations.
```php
<?php
$opt = Console::select('apply this patch?',
['y' => 'yes', 'n' => 'no', 'a' => 'all']
);
```
### Console::work(callable $callable)
Forks another process to run `$callable` in the background while showing status
updates to the standard output. By default the status update is a simple spinner
which will stop once the `$callable` returns. By providing `$callable` with a
`$socket` parameter, the status update is whatever is sent from the background
process to the foreground process using the `socket_write()` function:
```php
<?php
Console::stdout('Working ... ');
Console::work(function($socket) { // $socket is optional, defaults to a spinner
$n = 100;
for ($i = 1; $i <= $n; $i++) {
// do whatever it is you need to do
socket_write($socket, "[$i/$n]\n");
sleep(1); // sleep is good for you
}
});
Console::stdout("%g[DONE]%n\n");
```
Messages sent to the foreground process needs to end with a `"\n"` character.
### Text color and style specifiers
You can use text color and style specifiers in the format of `%x` where `x` is
the specifier:
```php
<?php
Console::output('this is %rcolored%n and %Bstyled%n');
```
The `%n` specifier normalizes the color and style of the text to that of the
shell's defaults. This specifier is taken from PEAR's Console_Color package.
To print a percentage symbol, simply put two `%` characters. The following is
the full set of specifiers:
```
text text background
------------------------------------------------
%k %K %0 black dark grey black
%r %R %1 red bold red red
%g %G %2 green bold green green
%y %Y %3 yellow bold yellow yellow
%b %B %4 blue bold blue blue
%m %M %5 magenta bold magenta magenta
%p %P magenta (think: purple)
%c %C %6 cyan bold cyan cyan
%w %W %7 white bold white white
%F Blinking, Flashing
%U Underline
%8 Reverse
%_,%9 Bold
%n Resets the color
%% A single %
```
You can use these specifiers with methods that takes a string and outputs it.
## Daemon
The Daemon class provides helpers for starting and killing daemonized processes.
### Daemon::isRunning($pid)
Tests if a daemon is currently running or not. Returns true or false:
```php
<?php
use Clio\Daemon;
if (Daemon::isRunning('/path/to/process.pid')) {
echo "daemon is running.\n";
} else {
echo "daemon is not running.\n";
}
```
### Daemon::work(array $options, callable $callable)
Daemonize a `$callable` callable object. The `$options` key-value array must
contain `pid` as the path to the PID file:
```php
<?php
use Clio\Daemon;
if (Daemon::isRunning('/path/to/process.pid')) {
echo "daemon is already running.\n";
} else {
Daemon::work(array(
'pid' => '/path/to/process.pid', // required
'stdin' => '/dev/null', // defaults to /dev/null
'stdout' => '/path/to/stdout.txt', // defaults to /dev/null
'stderr' => '/path/to/stderr.txt', // defaults to php://stdout
),
function($stdin, $stdout, $stderr) { // these parameters are optional
while (true) {
// do whatever it is daemons do
sleep(1); // sleep is good for you
}
}
);
echo "daemon is now running.\n";
}
```
The PID file is an ordinary text file with the process ID as its only content.
It will be created by the library automatically if it doesn't exist. It is
highly recommended to put a call to `sleep` to ease the system load.
### Daemon::kill($pid, $delete = false)
Kill a daemonized process:
```php
<?php
use Clio\Daemon;
if (Daemon::isRunning('/path/to/process.pid')) {
echo "killing running daemon ...\n";
if (Daemon::kill('/path/to/process.pid')) {
echo "daemon killed.\n";
} else {
echo "failed killing daemon.\n";
}
} else {
echo "nothing to kill.\n";
}
```
If the second parameter is set to `true`, this function will try to delete the
PID file after successfully sending the process a kill signal.
## Acknowledgments
The text color and style specifiers are taken entirely from PEAR's Console_Color
class by Stefan Walk. The Daemon class is heavily inspired from Andy Thompson's
blog post on [daemonizing a PHP CLI script on a POSIX system][post].
## License
Clio is released under the [MIT License][MIT].
[Composer]: http://getcomposer.org/
[MIT]: http://en.wikipedia.org/wiki/MIT_License
[post]: http://andytson.com/blog/2010/05/daemonising-a-php-cli-script-on-a-posix-system/
-19
View File
@@ -1,19 +0,0 @@
{
"name": "clio/clio",
"description": "Lightweight utility and helper classes for CLI applications",
"keywords": ["cli", "console", "daemon"],
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Nofriandi Ramenta",
"email": "nramenta@gmail.com"
}
],
"require": {
"php": ">=5.3.2"
},
"autoload": {
"psr-0": {"Clio": "src/"}
}
}
-476
View File
@@ -1,476 +0,0 @@
<?php
namespace Clio;
class Console
{
/**
* Text foreground colors.
*/
protected static $FGCOLOR = array(
'black' => 30,
'red' => 31,
'green' => 32,
'brown' => 33,
'blue' => 34,
'purple' => 35,
'cyan' => 36,
'grey' => 37,
'yellow' => 33,
);
/**
* Text styling.
*/
protected static $STYLE = array(
'normal' => 0,
'bold' => 1,
'light' => 1,
'underscore' => 4,
'underline' => 4,
'blink' => 5,
'inverse' => 6,
'hidden' => 8,
'concealed' => 8,
);
/**
* Text background color.
*/
protected static $BGCOLOR = array(
'black' => 40,
'red' => 41,
'green' => 42,
'brown' => 43,
'yellow' => 43,
'blue' => 44,
'purple' => 45,
'cyan' => 46,
'grey' => 47,
);
/**
* Color specifier conversion table. Taken from PEAR's Console_Color.
*/
protected static $CONVERSIONS = array(
'%y' => array('yellow', null, null),
'%g' => array('green', null, null),
'%b' => array('blue', null, null),
'%r' => array('red', null, null),
'%p' => array('purple', null, null),
'%m' => array('purple', null, null),
'%c' => array('cyan', null, null),
'%w' => array('grey', null, null),
'%k' => array('black', null, null),
'%n' => array('reset', null, null),
'%Y' => array('yellow', 'light', null),
'%G' => array('green', 'light', null),
'%B' => array('blue', 'light', null),
'%R' => array('red', 'light', null),
'%P' => array('purple', 'light', null),
'%M' => array('purple', 'light', null),
'%C' => array('cyan', 'light', null),
'%W' => array('grey', 'light', null),
'%K' => array('black', 'light', null),
'%N' => array('reset', 'light', null),
'%3' => array(null, null, 'yellow'),
'%2' => array(null, null, 'green'),
'%4' => array(null, null, 'blue'),
'%1' => array(null, null, 'red'),
'%5' => array(null, null, 'purple'),
'%6' => array(null, null, 'cyan'),
'%7' => array(null, null, 'grey'),
'%0' => array(null, null, 'black'),
// Don't use this, I can't stand flashing text
'%F' => array(null, 'blink', null),
'%U' => array(null, 'underline', null),
'%8' => array(null, 'inverse', null),
'%9' => array(null, 'bold', null),
'%_' => array(null, 'bold', null),
);
/**
* Create ANSI-control codes for text foreground and background colors, and
* styling.
*
* @param string $fgcolor Text foreground color
* @param string $style Text style
* @param string $bgcolor Text background color
*
* @return string ANSI-control code
*/
public static function color($fgcolor, $style, $bgcolor)
{
$code = array();
if ($fgcolor == 'reset') {
return "\033[0m";
}
if (isset(static::$FGCOLOR[$fgcolor])) {
$code[] = static::$FGCOLOR[$fgcolor];
}
if (isset(static::$STYLE[$style])) {
$code[] = static::$STYLE[$style];
}
if (isset(static::$BGCOLOR[$bgcolor])) {
$code[] = static::$BGCOLOR[$bgcolor];
}
if (empty($code)) {
$code[] = 0;
}
return "\033[" . implode(';', $code) . 'm';
}
/**
* Taken from PEAR's Console_Color:
*
* Converts colorcodes in the format %y (for yellow) into ansi-control
* codes. The conversion table is: ('bold' meaning 'light' on some
* terminals). It's almost the same conversion table irssi uses.
* <pre>
* text text background
* ------------------------------------------------
* %k %K %0 black dark grey black
* %r %R %1 red bold red red
* %g %G %2 green bold green green
* %y %Y %3 yellow bold yellow yellow
* %b %B %4 blue bold blue blue
* %m %M %5 magenta bold magenta magenta
* %p %P magenta (think: purple)
* %c %C %6 cyan bold cyan cyan
* %w %W %7 white bold white white
*
* %F Blinking, Flashing
* %U Underline
* %8 Reverse
* %_,%9 Bold
*
* %n Resets the color
* %% A single %
* </pre>
* First param is the string to convert, second is an optional flag if
* colors should be used. It defaults to true, if set to false, the
* colorcodes will just be removed (And %% will be transformed into %)
*
* @param string $text String to color
*
* @return string
*/
public static function colorize($text, $color = true)
{
$text = str_replace('%%', '% ', $text);
foreach (static::$CONVERSIONS as $key => $value) {
list($fgcolor, $style, $bgcolor) = $value;
$text = str_replace(
$key,
$color ? static::color($fgcolor, $style, $bgcolor) : '',
$text
);
}
return str_replace('% ', '%', $text);
}
/**
* Strips a string from color specifiers.
*
* @param string $text String to strip
*
* @return string
*/
public static function decolorize($text)
{
return static::colorize($text, false);
}
/**
* Strips a string of ansi-control codes.
*
* @param string $text String to strip
*
* @return string
*/
public static function strip($text)
{
return preg_replace('/\033\[(\d+)(;\d+)*m/', '', $text);
}
/**
* Gets input from STDIN and returns a string right-trimmed for EOLs.
*
* @param bool $raw If set to true, returns the raw string without trimming
*
* @return string
*/
public static function stdin($raw = false)
{
return $raw ? fgets(STDIN) : rtrim(fgets(STDIN), PHP_EOL);
}
/**
* Asks the user for input. Ends when the user types a PHP_EOL. Optionally
* provide a prompt.
*
* @param string $prompt String prompt (optional)
* @param bool $raw If set to true, returns the raw string without trimming
*
* @return string User input
*/
public static function input($prompt = null, $raw = false)
{
if (isset($prompt)) {
static::stdout($prompt);
}
return static::stdin($raw);
}
/**
* Prints text to STDOUT.
*
* @param string $text String to write to STDOUT
* @param bool $raw Write string as-is; defaults to false
*
* @return int|false Number of bytes printed or false on error
*/
public static function stdout($text, $raw = false)
{
if ($raw) {
return fwrite(STDOUT, $text);
} elseif (extension_loaded('posix') && posix_isatty(STDOUT)) {
return fwrite(STDOUT, static::colorize($text));
} else {
return fwrite(STDOUT, static::decolorize($text));
}
}
/**
* Prints text to STDOUT appended with a PHP_EOL.
*
* @param string $text String to write to STDOUT
* @param bool $raw Write string as-is; defaults to false
*
* @return int|false Number of bytes printed or false on error
*/
public static function output($text = null, $raw = false)
{
return static::stdout($text . PHP_EOL, $raw);
}
/**
* Prints text to STDERR.
*
* @param string $text String to write to STDERR
* @param bool $raw Write string as-is; defaults to false
*
* @return int|false Number of bytes printed or false on error
*/
public static function stderr($text, $raw = false)
{
if ($raw) {
return fwrite(STDERR, $text);
} elseif (extension_loaded('posix') && posix_isatty(STDERR)) {
return fwrite(STDERR, static::colorize($text));
} else {
return fwrite(STDERR, static::decolorize($text));
}
}
/**
* Prints text to STDERR appended with a PHP_EOL.
*
* @param string $text String to write to STDERR
* @param bool $raw Write string as-is; defaults to false
*
* @return int|false Number of bytes printed or false on error
*/
public static function error($text = null, $raw = false)
{
return static::stderr($text . PHP_EOL, $raw);
}
/**
* Prompts the user for input
*
* @param string $text Prompt string
* @param array $options Set of options
*
* @return string
*/
public static function prompt($text, $options = array())
{
$options = $options + array(
'required' => false,
'default' => null,
'pattern' => null,
'validator' => null,
'error' => 'Input unacceptable.',
);
top:
if ($options['default']) {
$input = static::input("$text [" . $options['default'] . ']: ');
} else {
$input = static::input("$text: ");
}
if (!strlen($input)) {
if (isset($options['default'])) {
$input = $options['default'];
} elseif ($options['required']) {
static::output($options['error']);
goto top;
}
} elseif ($options['pattern'] && !preg_match($options['pattern'], $input)) {
static::output($options['error']);
goto top;
} elseif ($options['validator'] &&
!call_user_func_array($options['validator'], array($input, &$error))) {
static::output(isset($error) ? $error : $options['error']);
goto top;
}
return $input;
}
/**
* Asks the user for a simple yes/no confirmation.
*
* @param string $text Prompt string
*
* @return bool Either true or false
*/
public static function confirm($text)
{
top:
$input = strtolower(static::input("$text [y/n]: "));
if (!in_array($input, array('y', 'n'))) goto top;
return $input === 'y' ? true : false;
}
/**
* Gives the user an option to choose from. Giving '?' as an input will show
* a list of options to choose from and their explanations.
*
* @param string $text Prompt string
* @param array $options Key-value array of options to choose from
*
* @return string An option character the user chose
*/
public static function select($text, $options = array())
{
top:
static::stdout("$text [" . implode(',', array_keys($options)) . ",?]: ");
$input = static::stdin();
if ($input === '?') {
foreach ($options as $key => $value) {
echo " $key - $value\n";
}
echo " ? - Show help\n";
goto top;
} elseif (!in_array($input, array_keys($options))) goto top;
return $input;
}
/**
* Execute a Closure as another process in the background while showing a
* status update. The status update can be an indefinite spinner or a string
* periodically sent from the background process, depending on whether the
* provided Closure object has a $socket parameter or not. Messaging to the
* main process is done by socket_* functions. The return value is either
* the return value of the background process, or false if the process fork
* failed.
*
* @throws \Exception
*
* @param callable $callable Closure object
*
* @return int|false Process exit status
*/
public static function work(callable $callable)
{
if (!extension_loaded('pcntl')) {
throw new \Exception('pcntl extension required');
}
if (!extension_loaded('sockets')) {
throw new \Exception('sockets extension required');
}
$spinner = array('|', '/', '-', '\\');
$i = 0; $l = count($spinner);
$delay = 100000;
$func = new \ReflectionFunction($callable);
$socket = (bool)$func->getNumberOfParameters();
if ($socket) {
$sockets = array();
if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets) === false) {
return false;
}
}
$pid = pcntl_fork();
if ($pid > 0) {
$done = false;
$retval = 0;
pcntl_signal(SIGCHLD, function() use ($pid, &$done, &$retval) {
$child_pid = pcntl_waitpid($pid, $status);
if (pcntl_wifexited($status)) {
$retval = pcntl_wexitstatus($status);
}
$done = true;
});
if ($socket) {
$text = '';
while (!$done) {
$r = array($sockets[1]);
$w = null;
$e = null;
if ($status = socket_select($r, $w, $e, 0)) {
$data = socket_read($sockets[1], 4096, PHP_NORMAL_READ);
if ($data === false) {
throw new \Exception(
sprintf(
'socket write error %s',
socket_strerror(socket_last_error($sockets[1]))
)
);
}
echo str_repeat(chr(8), strlen($text));
$text = rtrim($data, "\n");
Console::stdout($text);
} else {
pcntl_signal_dispatch();
}
usleep($delay);
}
echo str_repeat(chr(8), strlen($text));
socket_close($sockets[0]);
socket_close($sockets[1]);
} else {
while (!$done) {
pcntl_signal_dispatch();
echo $spinner[$i];
usleep($delay);
echo chr(8);
$i = $i === $l - 1 ? 0 : $i + 1;
}
}
return $retval;
} elseif ($pid === 0) {
if ($socket) {
call_user_func($callable, $sockets[0]);
} else {
call_user_func($callable);
}
exit;
} else {
// Unable to fork process.
return false;
}
}
}
-156
View File
@@ -1,156 +0,0 @@
<?php
namespace Clio;
class Daemon
{
/**
* Daemonize a Closure object.
*
* @throws \Exception
*
* @param array $options Set of options
* @param callable $callable Closure object to daemonize
*
* @return bool True on success, throws an Exception otherwise
*/
public static function work(array $options, callable $callable)
{
if (!extension_loaded('pcntl')) {
throw new \Exception('pcntl extension required');
}
if (!extension_loaded('posix')) {
throw new \Exception('posix extension required');
}
if (!isset($options['pid'])) {
throw new \Exception('pid not specified');
}
$options = $options + array(
'stdin' => '/dev/null',
'stdout' => '/dev/null',
'stderr' => 'php://stdout',
);
if (($lock = @fopen($options['pid'], 'c+')) === false) {
throw new \Exception('unable to open pid file ' . $options['pid']);
}
if (!flock($lock, LOCK_EX | LOCK_NB)) {
throw new \Exception('could not acquire lock for ' . $options['pid']);
}
switch ($pid = pcntl_fork()) {
case -1:
throw new \Exception('unable to fork');
case 0:
break;
default:
fseek($lock, 0);
ftruncate($lock, 0);
fwrite($lock ,$pid);
fflush($lock);
return;
}
if (posix_setsid() === -1) {
throw new \Exception('failed to setsid');
}
fclose(STDIN);
fclose(STDOUT);
fclose(STDERR);
if (!($stdin = fopen($options['stdin'], 'r'))) {
throw new \Exception('failed to open STDIN ' . $options['stdin']);
}
if (!($stdout = fopen($options['stdout'], 'w'))) {
throw new \Exception('failed to open STDOUT ' . $options['stdout']);
}
if (!($stderr = fopen($options['stderr'], 'w'))) {
throw new \Exception('failed to open STDERR ' . $options['stderr']);
}
pcntl_signal(SIGTSTP, SIG_IGN);
pcntl_signal(SIGTTOU, SIG_IGN);
pcntl_signal(SIGTTIN, SIG_IGN);
pcntl_signal(SIGHUP, SIG_IGN);
call_user_func($callable, $stdin, $stdout, $stderr);
}
/**
* Checks whether a daemon process specified by its PID file is running.
*
* @throws \Exception
*
* @param string $file Daemon PID file
*
* @return bool True if the daemon is still running, false otherwise
*/
public static function isRunning($file)
{
if (!extension_loaded('posix')) {
throw new \Exception('posix extension required');
}
if (!is_readable($file)) {
return false;
}
if (($lock = @fopen($file, 'c+')) === false) {
throw new \Exception('unable to open pid file ' . $file);
}
if (flock($lock, LOCK_EX | LOCK_NB)) {
return false;
} else {
flock($lock, LOCK_UN);
return true;
}
}
/**
* Kills a daemon process specified by its PID file.
*
* @throws \Exception
*
* @param string $file Daemon PID file
* @param bool $delete Flag to delete PID file after killing
*
* @return bool True on success, false otherwise
*/
public static function kill($file, $delete = false)
{
if (!extension_loaded('posix')) {
throw new \Exception('posix extension required');
}
if (!is_readable($file)) {
throw new \Exception('unreadable pid file ' . $file);
}
if (($lock = @fopen($file, 'c+')) === false) {
throw new \Exception('unable to open pid file ' . $file);
}
if (flock($lock, LOCK_EX | LOCK_NB)) {
flock($lock, LOCK_UN);
throw new \Exception('process not running');
}
$pid = fgets($lock);
if (posix_kill($pid, SIGTERM)) {
if ($delete) unlink($file);
return true;
} else {
return false;
}
}
}
-1
View File
@@ -6,5 +6,4 @@ $vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Clio' => array($vendorDir . '/clio/clio/src'),
);
-11
View File
@@ -113,16 +113,6 @@ class ComposerStaticInit6f86a52ac31283ed9de8003da3458103
),
);
public static $prefixesPsr0 = array (
'C' =>
array (
'Clio' =>
array (
0 => __DIR__ . '/..' . '/clio/clio/src',
),
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'Normalizer' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
@@ -133,7 +123,6 @@ class ComposerStaticInit6f86a52ac31283ed9de8003da3458103
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6f86a52ac31283ed9de8003da3458103::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6f86a52ac31283ed9de8003da3458103::$prefixDirsPsr4;
$loader->prefixesPsr0 = ComposerStaticInit6f86a52ac31283ed9de8003da3458103::$prefixesPsr0;
$loader->classMap = ComposerStaticInit6f86a52ac31283ed9de8003da3458103::$classMap;
}, null, ClassLoader::class);
-48
View File
@@ -1,53 +1,5 @@
{
"packages": [
{
"name": "clio/clio",
"version": "0.1.8",
"version_normalized": "0.1.8.0",
"source": {
"type": "git",
"url": "https://github.com/nramenta/clio.git",
"reference": "6a9f600b73fa213e817d5c1e67a4641aecd156ef"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nramenta/clio/zipball/6a9f600b73fa213e817d5c1e67a4641aecd156ef",
"reference": "6a9f600b73fa213e817d5c1e67a4641aecd156ef",
"shasum": ""
},
"require": {
"php": ">=5.3.2"
},
"time": "2014-06-22T14:49:41+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"Clio": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nofriandi Ramenta",
"email": "nramenta@gmail.com"
}
],
"description": "Lightweight utility and helper classes for CLI applications",
"keywords": [
"cli",
"console",
"daemon"
],
"support": {
"issues": "https://github.com/nramenta/clio/issues",
"source": "https://github.com/nramenta/clio/tree/0.1.8"
},
"install-path": "../clio/clio"
},
{
"name": "fabpot/goutte",
"version": "v4.0.3",
+2 -11
View File
@@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '5aff4ac5a61935ccb58762958f7f3a39bf9370f9',
'reference' => '263efd5b65eb3add92fd984646c43d19558f3c4e',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -13,21 +13,12 @@
'__root__' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '5aff4ac5a61935ccb58762958f7f3a39bf9370f9',
'reference' => '263efd5b65eb3add92fd984646c43d19558f3c4e',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
'clio/clio' => array(
'pretty_version' => '0.1.8',
'version' => '0.1.8.0',
'reference' => '6a9f600b73fa213e817d5c1e67a4641aecd156ef',
'type' => 'library',
'install_path' => __DIR__ . '/../clio/clio',
'aliases' => array(),
'dev_requirement' => false,
),
'fabpot/goutte' => array(
'pretty_version' => 'v4.0.3',
'version' => '4.0.3.0',