It is very useful if you have some very long operation but don't want user to wait for it to end before loading page, so you start another process and exit current script. Or you can use this if you need to run a cron, but don't have access to server so you can't add cron jobs.
Here is code that starts another process:
- Code: Select all
<?php
$server = 'localhost';
$get = '/path_to_script.php';
$fp = fsockopen($server, 80);
fputs($fp, "GET {$get} HTTP/1.1\r\n");
fputs($fp, "Host: {$server}\r\n");
fputs($fp, "Connection: Close\r\n\r\n");
fclose($fp);
?>
Then your another script that will be opened in that process:
- Code: Select all
<?php
set_time_limit(0); // remove script timeout
ignore_user_abort(false); // make sure script works even if connection is closed
/// ... and then do your stuff
?>

