Forum Moderators: coopster
I've been running through some ideas like cron, but it's not something on a regular schedule and I'd rather not deal with it.
For some reason I keep thinking that I can sleep without using up any cpu cycles.
Basically, I want to tell the script to start on demand, and have it run at a throttled pace until it is complete, without browser interaction.
exec
system
passthru
to fire off the script and let it tick away. I have had trouble with these, always different issues each time so I can't really point out anything specific. We hacve used shell scripts to control some things, fire the shell script, the shell script fires the actual php script, then the shell script returns to the calling page. This has fixed some issues with these functions hanging and waiting for responses.
aside from those I can only think of cron and imposing a schedule on the script.
If you start a program using this function and want to leave it running in the background, you have to make sure that the output of that program is redirected to a file or some other output stream or else PHP will hang until the execution of the program ends.
Seems a little too easy, I thought parent processes always waited for completion of the children?
Added: I recently put in a queuing system with a cron that runs every minute to clean up any data that needs to be processed. Since I know the CPU time per "chunk" was from 6-8 seconds, I just set the cron to do the first 6 queued "chunks." (With a column in the database for 'importance' so different users/situations can bump their "chunks" higher in the list.)
I had originally thought it'd be a complex task, but it turned out to be quite straightforward. The most frustration was figuring out how to turn off headers for command line PHP scripts. Even with no output, my scripts were still spitting out "content-type: text/html" (By the way, it's the -q flag.)