cocur / background-process Goto Github PK
View Code? Open in Web Editor NEWStart processes in the background that continue running when the PHP process exists.
License: MIT License
Start processes in the background that continue running when the PHP process exists.
License: MIT License
Its Not Working on windows
I've implemented windows support, please allow me to create a pull request.
This is my fork: https://github.com/lambasoft/background-process/blob/master/src/BackgroundProcess.php
Commit: lambasoft@15ae58e
When running background commands (here is my code) in Windows PowerShell or cmd shell, the command fails and the error Fatal Error Unable to reattach to base address
is printed to STDOUT. This doesn't happen when running the same code under Git Bash, where the commands execute as intended. A typical command that I am running is "php m:\mik_mark\extras\scripts\postwritehooks\validate_mods.php", with some arguments to the validate_mods.php script added at runtime.
A quick google for that error brings back some issues surrounding Zend Opcache (like this one).
Has anyone seen this before or have any suggestions as to how work around it? I'm on Windows 7 Enterprise SP1 (64 bit). php -v produces:
PHP 5.6.2 (cli) (built: Oct 15 2014 14:55:48)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
How to stop process by ID?
I am using stable version.
Thanks.
$process = new BackgroundProcess('/usr/bin/php queue.php'); if ($process->isRunning(15371)) { $process->stop(); }
many shared hosters allow exec commands and we can use your library. but some of them has no access to "ps". so maybe it would be more compatible to check if running via posix_getpgid?
Hello im using php-fpm alpine docker
the isRunning function always says true because the output of this code :
$result = shell_exec(sprintf('ps %d 2>&1', $this->pid));
is something like this :
PID USER TIME COMMAND\n 1 root 0:00 {supervisord} /usr/bin/python2 /usr/bin/supervisord -n -c /etc/supervisord.conf\n 15 root 0:00 crond -f /dev/null\n 17 root 0:00 php-fpm: master process (/usr/local/etc/php-fpm.d/www.conf)\n 18 root 0:00 nginx: master process /usr/sbin/nginx -g daemon off; error_log /dev/stderr info;\n 19 nginx 0:00 nginx: worker process\n 20 nginx 0:00 nginx: worker process\n 21 nginx 0:00 php-fpm: pool www\n 22 nginx 0:00 php-fpm: pool www\n 23 nginx 0:00 php-fpm: pool www\n 114 root 0:00 /bin/bash\n 270 root 0:00 php artisan streams:uptime\n 275 root 0:00 ps 90\n
so the count check after (the if statement) always get TRUE because it returns mother than 2 rows
Hi,
I would know if possible to create one stable TAG.
I saw your last TAG is pre-release.
Is possible?
Thank you.
I have a code which is collecting data.
When I run your code, I got the PID but I dont get the data.
So, I check the background process with terminal and I found nothing with the same PID.
When I run manually with "php collect.php" command, my code run normally and I get the data.
Is there anything I miss?
Thanks.
This is my code.
$process = new BackgroundProcess("php /var/www/html/project_name/public/assets/collect.php"); $process->run(); echo sprintf('Crunching numbers in process %d', $process->getPid()); while ($process->isRunning()) { echo '.'; sleep(1); } echo "\nDone.\n";
Hi,
$firstWords = "Hello World";
$process = new BackgroundProcess('/usr/local/bin/php /home/[...]/test.php');
test.php:
echo "This is first words: ".$firstWords; // print: "This is first words: ";
The strings do not reach the other page. I wanted to use argv in Cron for this. (link) it still did not work.
what is your idea on this issue?
Thanks
hi,
i try to use $phar->buildFromDirectory($path.'/'.$url)
in the backgroundProcess, but got an error
Notice: Array to string conversion
ContextErrorException
--
Symfony\Component\Debug\Exception\ContextErrorException: Notice: Array to string conversion at vendor/cocur/background-process/src/BackgroundProcess.php:74 at Cocur\BackgroundProcess\BackgroundProcess->run() (src/AppBundle/Controller/DefaultController.php:86) at AppBundle\Controller\DefaultController->AjaxAction(object(Request)) at call_user_func_array(array(object(DefaultController), 'AjaxAction'), array(object(Request))) (var/cache/dev/classes.php:4507) at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1) (var/cache/dev/classes.php:4462) at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true) (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:169) at Symfony\Component\HttpKernel\Kernel->handle(object(Request)) (web/app_dev.php:14)
the result of the $phar->buildFromDirectory is an array by default
When shell_exec has been disabled through the "disable_functions" php-setting, the run-method silently fails and sets pid = 0
.
This happens as you cast to integer
on the following line:
https://github.com/cocur/background-process/blob/master/src/BackgroundProcess.php#L74
shell_exec
returns null
when an error occurs - (int) null === 0
.
A RuntimeException should be thrown if shell_exec returns null
.
Code
$report = $job->createReport()
In $report setted object JobReport, but not filled
Is there a feature in php 5.6 that is required to make this run? Can you update this to php >= 5.4 in composer.json unless you really need a feature only available in 5.6 ?
As a work around, will use version 0.5.
Hi,
Thank you for this script.
I try to integrate it into codeiginiter but I don't know how.
Can some one helpme to do this.
Thank you.
How can I make this work on windows wamp? Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.