Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a forever.js equivalent for PHP to run my scripts continuously?

I occasionally use forever.js for quick and dirty deploying of CLI type Node.js applications to production environments where I don't want a full on supervisord deployment.

I was wondering if there was an equivalent for PHP? At the moment we have a queue processing system that get's messages from SQS and processes them synchronously into a database (it can't be done async as that causes all sorts of nasty row locking issues in this particular use case.) At the moment it runs ever minute using cron, but it often finishes early and I want it to start running again. I can't have more than one process running at a time.

Any *nix command/software/bash type ideas are welcome.

like image 708
Jujhar Singh Avatar asked Aug 14 '13 07:08

Jujhar Singh


People also ask

How do I make PHP scripts run forever?

You can make it run forever by either setting the value or call set_time_limit in your script (http://php.net/manual/en/function.set-time-limit.php).

What is forever npm?

What is forever? Forever is an npm module that ensures a Node. js script continuously runs in the background on the server. It's a helpful CLI tool for the production environment because it helps manage the Node applications and their processes.

How do I use npm forever?

Forever is an npm package used to keep your script running continuously in the background. It's a handy CLI tool that helps you to manage your application in the development and production stages. To start running a script with forever, use the forever start command, followed by the script name.


2 Answers

Just use forever with your php script (use the -c argument to instruct forever to use php):

$ cat test.php
<?php
sleep(3);
print("foobar\n");
exit;
?>
$ forever -c php test.php
foobar
error: Forever detected script was killed by signal: null
error: Forever restarting script for 1 time
foobar
error: Forever detected script was killed by signal: null
error: Forever restarting script for 2 time
...
like image 138
SheetJS Avatar answered Oct 12 '22 09:10

SheetJS


I've just discovered this tool supervisord and it works great. I've used this ratchet tutorial to make it run in minutes !

If I remember correctly forever script do not restart when you reboot server ?

like image 27
hugsbrugs Avatar answered Oct 12 '22 09:10

hugsbrugs