Reputation: 90921
I would like to be able to start a second script (either PHP or Python) when a page is loaded and have it continue to run after the user cancels/navigates away is this possible?
Upvotes: 2
Views: 323
Reputation: 11087
for keeping the current script:
for running another script:
Upvotes: 2
Reputation: 14642
You can send Connection:Close headers, which finishes the page for your user, but enables you to execute things "after page loads".
There is a simple way to ignore user abort (see php manual too):
ignore_user_abort(true);
Upvotes: 4
Reputation: 11382
Another approach if you can't use the others is to include an img tag at the bottom of your output that requests a php page that does whatever it is you are wanting to do.
It will still show the loading animation though, so I think Karsten's suggestion is probably better (I'll try that next time I need to do this type of thing I think).
Upvotes: 0
Reputation: 101731
Use process forking with pcntl. It only works under Unix operating systems, however.
You can also do something like this:
exec("/usr/bin/php ./child_script.php > /dev/null 2>&1 &");
You can read more about the above example here.
Upvotes: 2