Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting Apache kill background process

I have a script startbg.php:

echo `/usr/bin/php $dir/runbg.php >> $dir/logbg.txt 2>&1 &`;

Which I call from the web (via HTTP/Apache).

It runs runbg.php in a background process.

But if I restart Apache (/etc/init.d/apache2 restart), the background process is killed.

Is there anyway I can keep the process running in the background?

like image 636
Petah Avatar asked Nov 13 '22 00:11

Petah


1 Answers

You could open up an instance of PHP's internal webserver (As of PHP 5.4.0, the CLI SAPI provides a built-in web server.) in my test killing httpd.exe did not effect php.exe:8000

<?php 
//Tested with windows

chdir('../php');
//S = Server, listen interface 0.0.0.0 = all : port 8000
//t = Served document root
echo `php -S 0.0.0.0:8000 -t C:\\xampp\\htdocs >> C:\\xampp\\htdocs\\logbg.txt 2>&1 &`;
?>

So possibly (untested):

echo `/usr/bin/php -S 0.0.0.0:8000 -t /srv/www/yoursite.com/public_html >> /srv/www/yoursite.com/public_html/logbg.txt 2>&1 &$dir/runbg.php >> $dir/logbg.txt 2>&1 &`;

Tho id have no idea how to kill it :s

like image 73
Lawrence Cherone Avatar answered Nov 15 '22 14:11

Lawrence Cherone