Sometimes I have a long task which I don't want the current PHP thread to wait for, and I've done something like the following. Passing data in a session is a little kludgy, but seems to work.
I have another similar application, except file1.php is not being accessed by the user's client, but by another server, and the user is only accessing the other server. As such, a session cookie will not be available to the session_start()
in file1.php, and it will have to create a separate session file for each occurrence.
What are other options to pass data to a background worker script? I am not passing huge amount of data, but it still will be 1kb or so.
file1.php
session_start();
$_SESSION['_xfr']=$_POST;
$status=exec($'/usr/bin/php -q /path/to/my/worker.php'.' '.session_id().' >/dev/null &');
echo('Tell client we are done.');
file2.php
session_id($argv[1]);//Set by parent
session_start();
$data=$_SESSION['_xfr'];
//Do some task