I've decided to broaden my offerings to clinets. I wanted to be able to create a mobile application as well as backend for it. I've decided to use Kinetise (www.kinetise.com). It's very cool, though I've got a problem. When my scripts are not so simple they take time to execute. I've written to Kinetise support and they told me to return response before executing whole script and leave the most time consuming parts until the response has been sent. Such solution will make performs native apps much smoother.
So I'm using Zend Framework 1.12, which is installed on Apache, PHP 5.3+ with MySQL.
The most time consuming tasks are actually dependent on external APIs (like checking ip adress, sending emails with external smtps, sending push notifications after some action has been taken), which may take time to repond. I could not find usable help on Google.
The solution I've found is to use exec like this:
Code: Select all
$command = "sleep(30); mail('email@domain.com','test','test body');";
try {
exec(sprintf('php -r "%s" &> /dev/null &',$command));
} catch ( Zend_Exception $e ) {
Zend_Registry::get('logger')->emerg($e->getMessage());
}
I've been trying also with standard php ob_start(), ob_flush(), flush() - with no luck. Acutally on desktop browser I have some progress, the page was displaying 1,2,3...10 in 1 seconds interval which was achieved using ob_flush, but it did not work as expected on mobile device. Mobile device was waiting for 11 seconds until it presented whole server response.
Do you have any ideas? Any working solutions? It does not have to be Zend Framework, I can switch to another framework.
The point is, I need to send response before finishing script execution.