|
Posted by NC on 09/22/06 16:14
Jonah Bishop wrote:
>
> I have a script that manipulates image data, and it takes
> a long time to run. I'd like to send this process to the
> background at the appropriate time, so that it can go do
> its job without holding up the user.
>
> I've seen something like this used:
>
> system("php myscript.php &");
>
> But the PHP manual entry for the system() function call
> indicates the following:
>
> "Note: 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."
>
> I don't expect this background script to output anything,
> but suppose an error occurs during execution? Will PHP
> get tied up as a result (trying to output an error message)?
There are at least two ways of dealing with this issue:
1. Redirect the script's output into a file:
system("php myscript.php & > myscriptlog.txt");
system("php myscript.php & >> myscriptlog.txt");
The former will write any output the script produces into
a newly created file myscriptlog.txt; the latter will append
output the script produces to myscriptlog.txt
2. Buffer the output at the beginning of the script and
discard it at the end:
@ob_start();
// the script goes here...
@ob_end_clean();
Cheers,
NC
Navigation:
[Reply to this message]
|