Hi,
I want to run a PHP Program in background for 24 hours
I think i can start the program using a Crone job and it will work for 24 hours by coding it
When i tried it with an infinite loop, my program takes 99% of CPU time
How can i implement this in better way avoding infinite while loop.
I waanna run some code snippet in the program continuously, ex: checking a Database Table for
new entries.
Which is the better way to achieve this eliminating server over heads.
Thanks in Advance
PHP Run proces
Moderator: General Moderators
Re: PHP Run proces
An infinite loop is the only way to keep a script running indefinitely. Make the script sleep at the end of each iteration to avoid it looping too fast and consuming all the CPU cycles.
http://www.php.net/manual/en/function.usleep.php
http://www.php.net/manual/en/function.usleep.php
Re: PHP Run proces
Hi,
I appreciate the solution. But see, i want to run more that 6 programs in infinite loop. Sometimes more than 10 programs needs to be exected in this way.
One program will start as a main program, and it will create more than 10 child programs (these are having infinite loops) . Crone can be used for thsi or not ?? please give a good solution .
Thanks
I appreciate the solution. But see, i want to run more that 6 programs in infinite loop. Sometimes more than 10 programs needs to be exected in this way.
One program will start as a main program, and it will create more than 10 child programs (these are having infinite loops) . Crone can be used for thsi or not ?? please give a good solution .
Thanks
Re: PHP Run proces
I would go for gearman. You can have a trigger to run jobs (might be background jobs) on new entry. Go and read some more on gearman and see if it will work out for you. 
Re: PHP Run proces
Yeah i agree.
But i tried google and find some useful resources regarding process forging. Then i developed one simple PHP Library for running background multiple processes. Hope this will be useful for creating threads / background process in easy way .
http://whyscript.com/packages/OSX/
See this
Thanks
But i tried google and find some useful resources regarding process forging. Then i developed one simple PHP Library for running background multiple processes. Hope this will be useful for creating threads / background process in easy way .
http://whyscript.com/packages/OSX/
See this
Thanks