continuous PHP script
The reason am doing it this way is I need it to react at certain times of day within accuracy of a few seconds, something I can't achieve with cron jobs, and also it is not the same schedule every day, each day there is a different set of times I need the tasks to run.
Regards,
Geoff
9 Replies
If it is email or web generated, it should be easy to have it trigger an event which causes it to be processed. The trigger could be a shell, Perl or other script which can call PHP if necessary to perform the action.
Not really enough info provided.
Does anybody remember that name of the PHP framework for writing daemons? The one whose philosophy was something like "PHP usually isn't the best thing to do this in, but if you have to, this will make it as easy as possible"?
@Guspaz:
How is it reacting? If it's listening for incoming packets or connections, you should be using socket_select(), which will block waiting on activity on any of the sockets, and immediately wake up your app when there is activity. It also has a timeout, so you could set it to time out once a second to do other stuff periodically, for example.
Does anybody remember that name of the PHP framework for writing daemons? The one whose philosophy was something like "PHP usually isn't the best thing to do this in, but if you have to, this will make it as easy as possible"?
Warning, have lube on standby. Doing this kind of thing in PHP is not gentle.
PS: Writing the IRC bot was a fun exercise. Funny how a lot of the programming-for-fun that I do falls into the "useless or unnecessary but fun" category. Loading plugins dynamically by including them when executed, for example, is basically a memory leak. Running the plugins in a separate instance of the PHP interpreter with a standardized manner of passing information back and forth, on the other hand, worked better.
@Guspaz:
I wrote a long-lived PHP daemon back in the day (years ago, an IRC bot that managed some channels, supported custom plugins, etc) and it seemed to work pretty well. What makes PHP or Java well or poorly suited for writing a daemon? Is it just a matter of an inefficient garbage collector or something?
PS: Writing the IRC bot was a fun exercise. Funny how a lot of the programming-for-fun that I do falls into the "useless or unnecessary but fun" category. Loading plugins dynamically by including them when executed, for example, is basically a memory leak. Running the plugins in a separate instance of the PHP interpreter with a standardized manner of passing information back and forth, on the other hand, worked better.
Mmm, GC is actually nicely done in 5.3+, that's not the real issue - threading/forking is when you start getting into very very painful things. Single-threaded daemons that don't mind blocking is fine, but non-blocking execution is absolutely frightening.
(I wrote my own IRC bot in php as well, turned out quite well with uptimes of up to two months without leakage or breakdowns of any sort, and was a great learning experience - am currently rewriting her in node.js to learn node itself, and take advantage of node's async behavior)