PHP Run proces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

PHP Run proces

Post by kirank »

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
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: PHP Run proces

Post by Eran »

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
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Re: PHP Run proces

Post by kirank »

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
User avatar
Zlobcho
Forum Newbie
Posts: 18
Joined: Sun Jun 21, 2009 7:57 pm

Re: PHP Run proces

Post by Zlobcho »

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. :)
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Re: PHP Run proces

Post by kirank »

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
Post Reply