initial commit of SVN release repo
This commit is contained in:
5
inc/vendor/cocur/background-process/.gitignore
vendored
Normal file
5
inc/vendor/cocur/background-process/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/build/
|
||||
/vendor/
|
||||
/composer.lock
|
||||
/phpunit.xml
|
||||
/tests/fixtures/*.log
|
162
inc/vendor/cocur/background-process/.scrutinizer.yml
vendored
Normal file
162
inc/vendor/cocur/background-process/.scrutinizer.yml
vendored
Normal file
@ -0,0 +1,162 @@
|
||||
tools:
|
||||
external_code_coverage: true
|
||||
php_sim: true
|
||||
php_pdepend: true
|
||||
php_analyzer: true
|
||||
|
||||
filter:
|
||||
excluded_paths:
|
||||
- 'tests/*'
|
||||
- 'examples/*'
|
||||
|
||||
checks:
|
||||
php:
|
||||
verify_property_names: true
|
||||
verify_argument_usable_as_reference: true
|
||||
verify_access_scope_valid: true
|
||||
variable_existence: true
|
||||
useless_calls: true
|
||||
use_statement_alias_conflict: true
|
||||
use_self_instead_of_fqcn: true
|
||||
uppercase_constants: true
|
||||
unused_variables: true
|
||||
unused_properties: true
|
||||
unused_parameters: true
|
||||
unused_methods: true
|
||||
unreachable_code: true
|
||||
too_many_arguments: true
|
||||
symfony_request_injection: true
|
||||
switch_fallthrough_commented: true
|
||||
sql_injection_vulnerabilities: true
|
||||
spacing_of_function_arguments: true
|
||||
spacing_around_non_conditional_operators: true
|
||||
spacing_around_conditional_operators: true
|
||||
space_after_cast: true
|
||||
single_namespace_per_use: true
|
||||
simplify_boolean_return: true
|
||||
side_effects_or_types: true
|
||||
security_vulnerabilities: true
|
||||
scope_indentation:
|
||||
spaces_per_level: '4'
|
||||
return_doc_comments: true
|
||||
return_doc_comment_if_not_inferrable: true
|
||||
require_scope_for_properties: true
|
||||
require_scope_for_methods: true
|
||||
require_php_tag_first: true
|
||||
require_braces_around_control_structures: true
|
||||
remove_trailing_whitespace: true
|
||||
remove_php_closing_tag: true
|
||||
remove_extra_empty_lines: true
|
||||
psr2_switch_declaration: true
|
||||
psr2_control_structure_declaration: true
|
||||
psr2_class_declaration: true
|
||||
property_assignments: true
|
||||
properties_in_camelcaps: true
|
||||
prefer_while_loop_over_for_loop: true
|
||||
prefer_unix_line_ending: true
|
||||
prefer_sapi_constant: true
|
||||
precedence_mistakes: true
|
||||
precedence_in_conditions: true
|
||||
phpunit_assertions: true
|
||||
php5_style_constructor: true
|
||||
parameters_in_camelcaps: true
|
||||
parameter_non_unique: true
|
||||
parameter_doc_comments: true
|
||||
param_doc_comment_if_not_inferrable: true
|
||||
overriding_private_members: true
|
||||
optional_parameters_at_the_end: true
|
||||
one_class_per_file: true
|
||||
non_commented_empty_catch_block: true
|
||||
no_unnecessary_if: true
|
||||
no_unnecessary_function_call_in_for_loop: true
|
||||
no_unnecessary_final_modifier: true
|
||||
no_underscore_prefix_in_properties: true
|
||||
no_underscore_prefix_in_methods: true
|
||||
no_trait_type_hints: true
|
||||
no_trailing_whitespace: true
|
||||
no_space_inside_cast_operator: true
|
||||
no_space_between_concatenation_operator: true
|
||||
no_space_before_semicolon: true
|
||||
no_space_around_object_operator: true
|
||||
no_space_after_cast: true
|
||||
no_short_open_tag: true
|
||||
no_property_on_interface: true
|
||||
no_non_implemented_abstract_methods: true
|
||||
code_rating: true
|
||||
duplication: true
|
||||
deprecated_code_usage: true
|
||||
closure_use_not_conflicting: true
|
||||
closure_use_modifiable: true
|
||||
avoid_useless_overridden_methods: true
|
||||
avoid_conflicting_incrementers: true
|
||||
assignment_of_null_return: true
|
||||
no_goto: true
|
||||
no_global_keyword: true
|
||||
no_exit: true
|
||||
no_eval: true
|
||||
no_error_suppression: true
|
||||
no_empty_statements: true
|
||||
no_elseif_statements: true
|
||||
no_duplicate_arguments: true
|
||||
no_debug_code: true
|
||||
no_commented_out_code: true
|
||||
newline_at_end_of_file: true
|
||||
naming_conventions:
|
||||
local_variable: '^[a-z][a-zA-Z0-9]*$'
|
||||
abstract_class_name: ^Abstract|Factory$
|
||||
utility_class_name: 'Utils?$'
|
||||
constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$'
|
||||
property_name: '^[a-z][a-zA-Z0-9]*$'
|
||||
method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$'
|
||||
parameter_name: '^[a-z][a-zA-Z0-9]*$'
|
||||
interface_name: '^[A-Z][a-zA-Z0-9]*Interface$'
|
||||
type_name: '^[A-Z][a-zA-Z0-9]*$'
|
||||
exception_name: '^[A-Z][a-zA-Z0-9]*Exception$'
|
||||
isser_method_name: '^(?:is|has|should|may|supports|filter)'
|
||||
more_specific_types_in_doc_comments: true
|
||||
missing_arguments: true
|
||||
method_calls_on_non_object: true
|
||||
lowercase_php_keywords: true
|
||||
lowercase_basic_constants: true
|
||||
instanceof_class_exists: true
|
||||
function_in_camel_caps: true
|
||||
function_body_start_on_new_line: true
|
||||
foreach_usable_as_reference: true
|
||||
foreach_traversable: true
|
||||
fix_use_statements:
|
||||
remove_unused: true
|
||||
preserve_multiple: false
|
||||
preserve_blanklines: false
|
||||
order_alphabetically: true
|
||||
fix_php_opening_tag: true
|
||||
fix_linefeed: true
|
||||
fix_line_ending: true
|
||||
fix_identation_4spaces: true
|
||||
fix_doc_comments: true
|
||||
ensure_lower_case_builtin_functions: true
|
||||
encourage_single_quotes: true
|
||||
encourage_shallow_comparison: true
|
||||
encourage_postdec_operator: true
|
||||
deadlock_detection_in_loops: true
|
||||
classes_in_camel_caps: true
|
||||
catch_class_exists: true
|
||||
blank_line_after_namespace_declaration: true
|
||||
avoid_usage_of_logical_operators: true
|
||||
avoid_unnecessary_concatenation: true
|
||||
avoid_todo_comments: true
|
||||
avoid_tab_indentation: true
|
||||
avoid_superglobals: true
|
||||
avoid_perl_style_comments: true
|
||||
avoid_fixme_comments: true
|
||||
avoid_length_functions_in_loops: true
|
||||
avoid_multiple_statements_on_same_line: true
|
||||
avoid_entity_manager_injection: true
|
||||
avoid_duplicate_types: true
|
||||
avoid_corrupting_byteorder_marks: true
|
||||
avoid_closing_tag: true
|
||||
avoid_aliased_php_functions: true
|
||||
align_assignments: true
|
||||
argument_type_checks: true
|
||||
no_mixed_inline_html: true
|
||||
no_long_variable_names:
|
||||
maximum: '20'
|
31
inc/vendor/cocur/background-process/.travis.yml
vendored
Normal file
31
inc/vendor/cocur/background-process/.travis.yml
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
language: php
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache/files
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.6
|
||||
- php: 5.6
|
||||
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable'
|
||||
- php: 7.0
|
||||
- php: hhvm
|
||||
- php: nightly
|
||||
allow_failures:
|
||||
- php: 7.0
|
||||
- php: nightly
|
||||
fast_finish: true
|
||||
|
||||
before_install:
|
||||
- travis_retry composer self-update && composer --version
|
||||
|
||||
install:
|
||||
- travis_retry composer update $COMPOSER_FLAGS --prefer-source -n
|
||||
|
||||
script: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover
|
||||
|
||||
after_script:
|
||||
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi;'
|
21
inc/vendor/cocur/background-process/LICENSE
vendored
Normal file
21
inc/vendor/cocur/background-process/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Florian Eckerstorfer
|
||||
|
||||
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.
|
6
inc/vendor/cocur/background-process/Makefile
vendored
Normal file
6
inc/vendor/cocur/background-process/Makefile
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
test:
|
||||
./vendor/bin/phpunit -c ./
|
||||
|
||||
code-coverage:
|
||||
./vendor/bin/phpunit -c ./ --coverage-html=./docs/generated/code-coverage
|
||||
open ./docs/generated/code-coverage/index.html
|
125
inc/vendor/cocur/background-process/README.md
vendored
Normal file
125
inc/vendor/cocur/background-process/README.md
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
cocur/background-process
|
||||
========================
|
||||
|
||||
> Start processes in the background that continue running when the PHP process exists.
|
||||
|
||||
[](https://packagist.org/packages/cocur/background-process)
|
||||
[](https://travis-ci.org/cocur/background-process)
|
||||
[](https://ci.appveyor.com/project/florianeckerstorfer/background-process)
|
||||
[](https://scrutinizer-ci.com/g/cocur/background-process/?branch=master)
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
You can install Cocur\BackgroundProcess using [Composer](http://getcomposer.org):
|
||||
|
||||
```shell
|
||||
$ composer require cocur/background-process
|
||||
```
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
The following example will execute the command `sleep 5` in the background. Thus, if you run the following script
|
||||
either in the browser or in the command line it will finish executing instantly.
|
||||
|
||||
```php
|
||||
use Cocur\BackgroundProcess\BackgroundProcess;
|
||||
|
||||
$process = new BackgroundProcess('sleep 5');
|
||||
$process->run();
|
||||
```
|
||||
|
||||
You can retrieve the process ID (PID) of the process and check if it's running:
|
||||
|
||||
```php
|
||||
use Cocur\BackgroundProcess\BackgroundProcess;
|
||||
|
||||
$process = new BackgroundProcess('sleep 5');
|
||||
$process->run();
|
||||
|
||||
echo sprintf('Crunching numbers in process %d', $process->getPid());
|
||||
while ($process->isRunning()) {
|
||||
echo '.';
|
||||
sleep(1);
|
||||
}
|
||||
echo "\nDone.\n";
|
||||
```
|
||||
|
||||
If the process runs you can stop it:
|
||||
|
||||
```php
|
||||
// ...
|
||||
if ($process->isRunning()) {
|
||||
$process->stop();
|
||||
}
|
||||
```
|
||||
|
||||
*Please note: If the parent process continues to run while the child process(es) run(s) in the background you should
|
||||
use a more robust solution, for example, the [Symfony Process](https://github.com/symfony/Process) component.*
|
||||
|
||||
### Windows Support
|
||||
|
||||
Since Version 0.5 Cocur\BackgroundProcess has basic support for Windows included. However, support is very limited at
|
||||
this time. You can run processes in the background, but it is not possible to direct the output into a file and you
|
||||
can not retrieve the process ID (PID), check if a process is running and stop a running process.
|
||||
|
||||
In practice, the following methods will throw an exception if called on a Windows system:
|
||||
|
||||
- `Cocur\BackgroundProcess\BackgroundProcess::getPid()`
|
||||
- `Cocur\BackgroundProcess\BackgroundProcess::isRunning()`
|
||||
- `Cocur\BackgroundProcess\BackgroundProcess::stop()`
|
||||
|
||||
### Create with existing PID
|
||||
|
||||
If you have a long running process and store its PID in the database you might want to check at a later point (when you don't have the BackgroundProcess object anymore) whether the process is still running and stop the process.
|
||||
|
||||
```php
|
||||
use Cocur\BackgroundProcess\BackgroundProcess;
|
||||
|
||||
$process = BackgroundProcess::createFromPID($pid);
|
||||
$process->isRunning(); // -> true
|
||||
$process->stop(); // -> true
|
||||
```
|
||||
|
||||
Change Log
|
||||
----------
|
||||
|
||||
### Version 0.7 (11 February 2017)
|
||||
|
||||
- [#19](https://github.com/cocur/background-process/pull/19) Create `BackgroundProcess` object from PID (by [socieboy](https://github.com/socieboy) and [florianeckerstorfer](https://github.com/florianeckerstorfer))
|
||||
|
||||
### Version 0.6 (10 July 2016)
|
||||
|
||||
- [#17](https://github.com/cocur/background-process/pull/17) Add ability to append to file on Unix/Linux-based systems (by [bpolaszek](https://github.com/bpolaszek))
|
||||
|
||||
### Version 0.5 (24 October 2015)
|
||||
|
||||
- Added basic support for Windows
|
||||
|
||||
### Version 0.4 (2 April 2014)
|
||||
|
||||
- Moved repository to Cocur organization
|
||||
- Changed namespace to `Cocur`
|
||||
- PSR-4 compatible namespace
|
||||
- [#3](https://github.com/cocur/background-process/pull/3) Added `BackgroundProcess::stop()` (by florianeckerstorfer)
|
||||
|
||||
### Version 0.3 (15 November 2013)
|
||||
|
||||
- Changed namespace to `Braincrafted`
|
||||
|
||||
|
||||
Author
|
||||
------
|
||||
|
||||
[**Florian Eckerstorfer**](http://florian.ec)
|
||||
|
||||
- [Twitter](http://twitter.com/Florian_)
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
The MIT license applies to **cocur/background-process**. For the full copyright and license information, please view the LICENSE file distributed with this source code.
|
33
inc/vendor/cocur/background-process/appveyor.yml
vendored
Normal file
33
inc/vendor/cocur/background-process/appveyor.yml
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
build: false
|
||||
shallow_clone: true
|
||||
platform: x86
|
||||
clone_folder: c:\projects\cocur\background-process
|
||||
|
||||
cache:
|
||||
- '%LOCALAPPDATA%\Composer\files'
|
||||
|
||||
init:
|
||||
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- COMPOSER_FLAGS: ""
|
||||
|
||||
install:
|
||||
- cinst -y OpenSSL.Light
|
||||
- cinst -y php
|
||||
- cd c:\tools\php
|
||||
- copy php.ini-production php.ini /Y
|
||||
- echo date.timezone="UTC" >> php.ini
|
||||
- echo extension_dir=ext >> php.ini
|
||||
- echo extension=php_openssl.dll >> php.ini
|
||||
- echo extension=php_mbstring.dll >> php.ini
|
||||
- echo extension=php_fileinfo.dll >> php.ini
|
||||
- echo memory_limit=1G >> php.ini
|
||||
- cd c:\projects\cocur\background-process
|
||||
- php -r "readfile('http://getcomposer.org/installer');" | php
|
||||
- php composer.phar update %COMPOSER_FLAGS% --no-interaction --no-progress
|
||||
|
||||
test_script:
|
||||
- cd c:\projects\cocur\background-process
|
||||
- vendor\bin\phpunit.bat --verbose
|
18
inc/vendor/cocur/background-process/composer.json
vendored
Normal file
18
inc/vendor/cocur/background-process/composer.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "cocur/background-process",
|
||||
"description": "Start processes in the background that continue running when the PHP process exists.",
|
||||
"type": "library",
|
||||
"keywords": ["process", "background", "unix"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": ">=5.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.8|~5.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Cocur\\BackgroundProcess\\": "src/"
|
||||
}
|
||||
}
|
||||
}
|
15
inc/vendor/cocur/background-process/phpunit.xml.dist
vendored
Normal file
15
inc/vendor/cocur/background-process/phpunit.xml.dist
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="cocur/background-process Test Suite">
|
||||
<directory>tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
198
inc/vendor/cocur/background-process/src/BackgroundProcess.php
vendored
Normal file
198
inc/vendor/cocur/background-process/src/BackgroundProcess.php
vendored
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of cocur/background-process.
|
||||
*
|
||||
* (c) 2013-2015 Florian Eckerstorfer
|
||||
*/
|
||||
|
||||
namespace Cocur\BackgroundProcess;
|
||||
|
||||
use Exception;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* BackgroundProcess.
|
||||
*
|
||||
* Runs a process in the background.
|
||||
*
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
|
||||
* @copyright 2013-2015 Florian Eckerstorfer
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @link https://florian.ec/articles/running-background-processes-in-php/ Running background processes in PHP
|
||||
*/
|
||||
class BackgroundProcess
|
||||
{
|
||||
const OS_WINDOWS = 1;
|
||||
const OS_NIX = 2;
|
||||
const OS_OTHER = 3;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $command;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $pid;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $serverOS;
|
||||
|
||||
/**
|
||||
* @param string $command The command to execute
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __construct($command = null)
|
||||
{
|
||||
$this->command = $command;
|
||||
$this->serverOS = $this->getOS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the command in a background process.
|
||||
*
|
||||
* @param string $outputFile File to write the output of the process to; defaults to /dev/null
|
||||
* currently $outputFile has no effect when used in conjunction with a Windows server
|
||||
* @param bool $append - set to true if output should be appended to $outputfile
|
||||
*/
|
||||
public function run($outputFile = '/dev/null', $append = false)
|
||||
{
|
||||
if($this->command === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ($this->getOS()) {
|
||||
case self::OS_WINDOWS:
|
||||
if (class_exists("COM")) {
|
||||
$shell = new \COM("WScript.Shell");
|
||||
$shell->CurrentDirectory = realpath(DOC_ROOT . "/exec");
|
||||
$shell->run("cmd /C \"{$this->command}\"", 0, false);
|
||||
} else {
|
||||
shell_exec(sprintf('"cd ' . realpath(DOC_ROOT . "/exec") . ' && %s %s %s"', $this->command, ($append ? '>>' : '>'), $outputFile));
|
||||
}
|
||||
break;
|
||||
case self::OS_NIX:
|
||||
$script = "cd " . realpath(DOC_ROOT . "/exec") . " && " .
|
||||
sprintf('%s %s %s 2>&1 &', $this->command, ($append ? ">>" : ">"), $outputFile);
|
||||
pclose(popen($script, "r"));
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException(sprintf(
|
||||
'Could not execute command "%s" because operating system "%s" is not supported by '.
|
||||
'Cocur\BackgroundProcess.', $this->command, PHP_OS
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the process is currently running.
|
||||
*
|
||||
* @return bool TRUE if the process is running, FALSE if not.
|
||||
*/
|
||||
public function isRunning()
|
||||
{
|
||||
$this->checkSupportingOS('Cocur\BackgroundProcess can only check if a process is running on *nix-based '.
|
||||
'systems, such as Unix, Linux or Mac OS X. You are running "%s".');
|
||||
|
||||
try {
|
||||
$result = shell_exec(sprintf('ps %d 2>&1', $this->pid));
|
||||
if (count(preg_split("/\n/", $result)) > 2 && !preg_match('/ERROR: Process ID out of range/', $result)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the process.
|
||||
*
|
||||
* @return bool `true` if the processes was stopped, `false` otherwise.
|
||||
*/
|
||||
public function stop()
|
||||
{
|
||||
$this->checkSupportingOS('Cocur\BackgroundProcess can only stop a process on *nix-based systems, such as '.
|
||||
'Unix, Linux or Mac OS X. You are running "%s".');
|
||||
|
||||
try {
|
||||
$result = shell_exec(sprintf('kill %d 2>&1', $this->pid));
|
||||
if (!preg_match('/No such process/', $result)) {
|
||||
return true;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID of the process.
|
||||
*
|
||||
* @return int The ID of the process
|
||||
*/
|
||||
public function getPid()
|
||||
{
|
||||
$this->checkSupportingOS('Cocur\BackgroundProcess can only return the PID of a process on *nix-based systems, '.
|
||||
'such as Unix, Linux or Mac OS X. You are running "%s".');
|
||||
|
||||
return $this->pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the process id.
|
||||
*
|
||||
* @param $pid
|
||||
*/
|
||||
protected function setPid($pid)
|
||||
{
|
||||
$this->pid = $pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
protected function getOS()
|
||||
{
|
||||
$os = strtoupper(PHP_OS);
|
||||
|
||||
if (substr($os, 0, 3) === 'WIN') {
|
||||
return self::OS_WINDOWS;
|
||||
} elseif ($os === 'LINUX' || $os === 'FREEBSD' || $os === 'DARWIN') {
|
||||
return self::OS_NIX;
|
||||
}
|
||||
|
||||
return self::OS_OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $message Exception message if the OS is not supported
|
||||
*
|
||||
* @throws RuntimeException if the operating system is not supported by Cocur\BackgroundProcess
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function checkSupportingOS($message)
|
||||
{
|
||||
if ($this->getOS() !== self::OS_NIX) {
|
||||
throw new RuntimeException(sprintf($message, PHP_OS));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $pid PID of process to resume
|
||||
*
|
||||
* @return Cocur\BackgroundProcess\BackgroundProcess
|
||||
*/
|
||||
static public function createFromPID($pid) {
|
||||
$process = new self();
|
||||
$process->setPid($pid);
|
||||
|
||||
return $process;
|
||||
}
|
||||
}
|
34
inc/vendor/cocur/background-process/src/Factory.php
vendored
Normal file
34
inc/vendor/cocur/background-process/src/Factory.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of cocur/background-process.
|
||||
*
|
||||
* (c) 2013-2104 Florian Eckerstorfer
|
||||
*/
|
||||
|
||||
namespace Cocur\BackgroundProcess;
|
||||
|
||||
/**
|
||||
* Factory to create BackgroundProcess objects.
|
||||
*
|
||||
* @package cocur/background-process
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
|
||||
* @copyright 2013-2014 Florian Eckerstorfer
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @link http://braincrafted.com/php-background-processes/ Running background processes in PHP
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
/** @var string */
|
||||
private $className;
|
||||
|
||||
public function __construct($className)
|
||||
{
|
||||
$this->className = $className;
|
||||
}
|
||||
|
||||
public function newProcess($command)
|
||||
{
|
||||
$className = $this->className;
|
||||
return new $className($command);
|
||||
}
|
||||
}
|
206
inc/vendor/cocur/background-process/tests/BackgroundProcessTest.php
vendored
Normal file
206
inc/vendor/cocur/background-process/tests/BackgroundProcessTest.php
vendored
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of cocur/background-process.
|
||||
*
|
||||
* (c) 2013-2014 Florian Eckerstorfer
|
||||
*/
|
||||
|
||||
namespace Cocur\BackgroundProcess;
|
||||
|
||||
/**
|
||||
* BackgroundProcessTest
|
||||
*
|
||||
* @category test
|
||||
* @package cocur/background-process
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
|
||||
* @copyright 2013-2104 Florian Eckerstorfer
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @group functional
|
||||
*/
|
||||
class BackgroundProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::run()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::isRunning()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getOS()
|
||||
*/
|
||||
public function runShouldRunCommand()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$command = sprintf('tests\\fixtures\\cmd.bat', __DIR__);
|
||||
} else {
|
||||
$command = sprintf('./tests/fixtures/cmd.sh', __DIR__);
|
||||
}
|
||||
|
||||
$checkFile = __DIR__.DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'runShouldRunCommand.log';
|
||||
|
||||
$process = new BackgroundProcess($command);
|
||||
$process->run();
|
||||
|
||||
sleep(1);
|
||||
|
||||
$this->assertStringStartsWith('ok', file_get_contents($checkFile));
|
||||
|
||||
unlink($checkFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::isRunning()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getOS()
|
||||
*/
|
||||
public function isRunningShouldReturnIfProcessIsRunning()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::isRunning() is not supported on '.
|
||||
'Windows.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 3');
|
||||
|
||||
$this->assertFalse($process->isRunning());
|
||||
$process->run();
|
||||
$this->assertTrue($process->isRunning());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::isRunning()
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function isRunningShouldThrowExceptionIfWindows()
|
||||
{
|
||||
if (!preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::isRunning() is supported on *nix '.
|
||||
'systems and does not need to throw an exception.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 1');
|
||||
$process->isRunning();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::run()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getOS()
|
||||
*/
|
||||
public function runShouldWriteOutputToFile()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::run() does not support writing output '.
|
||||
'into a file on Windows.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$outputFile = __DIR__.'/fixtures/runShouldWriteOutputToFile.log';
|
||||
|
||||
$process = new BackgroundProcess('ls');
|
||||
$process->run($outputFile);
|
||||
|
||||
sleep(1);
|
||||
$this->assertNotNull(file_get_contents($outputFile));
|
||||
unlink($outputFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getPid()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getOS()
|
||||
*/
|
||||
public function getPidShouldReturnPidOfProcess()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::getPid() is not supported on Windows.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 3');
|
||||
$process->run();
|
||||
|
||||
$this->assertNotNull($process->getPid());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getPid()
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function getPidShouldThrowExceptionIfWindows()
|
||||
{
|
||||
if (!preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::getPid() is supported on *nix systems '.
|
||||
'and does not need to throw an exception.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 1');
|
||||
$process->getPid();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::stop()
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::getOS()
|
||||
*/
|
||||
public function stopShouldStopRunningProcess()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::stop() is not supported on Windows.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 5');
|
||||
$process->run();
|
||||
|
||||
$this->assertTrue($process->stop());
|
||||
$this->assertFalse($process->isRunning());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::stop()
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function stopShouldThrowExceptionIfWindows()
|
||||
{
|
||||
if (!preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::stop() is supported on *nix systems '.
|
||||
'and does not need to throw an exception.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$process = new BackgroundProcess('sleep 1');
|
||||
$process->stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers Cocur\BackgroundProcess\BackgroundProcess::createFromPID()
|
||||
*/
|
||||
public function createFromPIDShouldCreateObjectFromPID()
|
||||
{
|
||||
if (preg_match('/^WIN/', PHP_OS)) {
|
||||
$this->markTestSkipped('Cocur\BackgroundProcess\BackgroundProcess::createFromPID() is not supported on Windows.');
|
||||
|
||||
return;
|
||||
}
|
||||
$process = new BackgroundProcess('sleep 1');
|
||||
$process->run();
|
||||
$pid = $process->getPid();
|
||||
|
||||
$newProcess = BackgroundProcess::createFromPID($pid);
|
||||
|
||||
$this->assertEquals($pid, $newProcess->getPid());
|
||||
$this->assertTrue($newProcess->stop());
|
||||
}
|
||||
}
|
41
inc/vendor/cocur/background-process/tests/FactoryTest.php
vendored
Normal file
41
inc/vendor/cocur/background-process/tests/FactoryTest.php
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of cocur/background-process.
|
||||
*
|
||||
* (c) 2013-2014 Florian Eckerstorfer
|
||||
*/
|
||||
|
||||
namespace Cocur\BackgroundProcess;
|
||||
|
||||
/**
|
||||
* FactoryTest
|
||||
*
|
||||
* @category test
|
||||
* @package cocur/background-process
|
||||
* @author Florian Eckerstorfer <florian@eckerstorfer.co>
|
||||
* @copyright 2013-2014 Florian Eckerstorfer
|
||||
* @license http://opensource.org/licenses/MIT The MIT License
|
||||
* @link http://braincrafted.com/php-background-processes/ Running background processes in PHP
|
||||
* @group unit
|
||||
*/
|
||||
class FactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var string */
|
||||
private $mockClass = 'Cocur\BackgroundProcess\MockBackgroundProcess';
|
||||
|
||||
/**
|
||||
* Tests the <code>newProcess</code> method.
|
||||
*
|
||||
* @covers Cocur\BackgroundProcess\Factory::__construct()
|
||||
* @covers Cocur\BackgroundProcess\Factory::newProcess()
|
||||
*/
|
||||
public function testNewProcess()
|
||||
{
|
||||
$factory = new Factory($this->mockClass);
|
||||
$this->assertInstanceOf($this->mockClass, $factory->newProcess('sleep 1'));
|
||||
}
|
||||
}
|
||||
|
||||
class MockBackgroundProcess
|
||||
{
|
||||
}
|
0
inc/vendor/cocur/background-process/tests/fixtures/.gitkeep
vendored
Normal file
0
inc/vendor/cocur/background-process/tests/fixtures/.gitkeep
vendored
Normal file
1
inc/vendor/cocur/background-process/tests/fixtures/cmd.bat
vendored
Normal file
1
inc/vendor/cocur/background-process/tests/fixtures/cmd.bat
vendored
Normal file
@ -0,0 +1 @@
|
||||
echo ok > tests\fixtures\runShouldRunCommand.log
|
3
inc/vendor/cocur/background-process/tests/fixtures/cmd.sh
vendored
Normal file
3
inc/vendor/cocur/background-process/tests/fixtures/cmd.sh
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "ok" > tests/fixtures/runShouldRunCommand.log
|
Reference in New Issue
Block a user