Reputation: 1060
Is there a way to make PHP request where user doesn't have to wait for response? Some sort of "php request in background"?
For example, if application needs to send 100 emails because the user had submitted something, I don't want to show "sending... please wait" for this user, but I want some other script to do the job independent from that user...
Upvotes: 2
Views: 3045
Reputation: 37633
Options:
Upvotes: 7
Reputation: 17441
Create a php routine to do the actual work of sending the emails and call it via http GET using the technique described here.
Upvotes: 0
Reputation: 141829
exec('php script.php > /dev/null & echo $!', $o);
You may want to use php-cli
instead of php
as well.
The command above returns the process id of the background script in $o[0] so you can set something up to poll it with ajax or somethig if you want to show the user it's progress.
Upvotes: 0
Reputation: 24661
You could send the request via ajax and then redirect the user elsewhere upon success. The server script will still process, but no confirmation will be given to the user.
Upvotes: 1
Reputation: 140753
You can maybe send the request in Ajax this way to UI won't freeze and the task will be executed on the server?
Upvotes: 3