I think it is possible to do the background execution using Curl as in the example below:
background-script.php
if ($_GET['iniciarbackground'] == 'true') { // chamada iniciada pelo ajax
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.yoursite.com/background-script.php');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
// repassar ao cURL, tudo que recebeu como POST:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
curl_exec($ch);
curl_close($ch);
} else { // chamada iniciada pelo cURL
// tarefas a executar no background
}
jquery:
$.post( "background-script.php?iniciarbackground=true", { name: "John", time: "2pm" } );
Source: http://www.paul-norman.co.uk/2009/06/asynchronous-curl-requests/
You could try using Threads (PHP) or take a look at it which may not be your problem, but is useful: http://css-tricks.com/multiple-simultaneous-ajax-requests-callback-jquery/
– Victor Martins
You could open a new window that fires that ajax and you’ll be waiting. Otherwise it could make the navigation happen on the same page, changing only the content of some parts of the page.
– Sergio
This would involve Messaging Pattern - SOA?
– neoprofit
Thank you guys so much!
– Marcelo Martins
It could just generate a "cron" schedule. Via PHP, create a cronjob or schtask (windows) and leave it scheduled to start the task in 1 minute. This way, the browser, the visual part of the user can browse without worry and without having to wait for the process. As for scheduling running on the server, when you complete, fire an email to the user or message, something like that to let them know you’ve completed. It’s just an idea.. I particularly use it a lot. I prefer it that way than asynchronous actions or the use of ignore_user_abort().
– Daniel Omine