PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 20, 2018 3:34 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Jul 14, 2015 1:23 am 
Offline
Forum Newbie

Joined: Tue Jul 14, 2015 1:19 am
Posts: 2
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.

Image

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:
Syntax: [ Download ] [ Hide ]
$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.

_________________
I've created this great mobile app in Kinetise in less than an hour! Check it out:
https://www.kinetise.com/sed2015


Top
 Profile  
 
PostPosted: Tue Jul 14, 2015 6:31 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
How many of these blocking responses do you actually need to wait for? Consider shunting some of it off to a queue.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Jul 14, 2015 4:37 pm 
Offline
Forum Newbie

Joined: Tue Jul 14, 2015 1:19 am
Posts: 2
There are actually a few blocking requests.

Almost each action generates few emails:
- Administration email
- Notification email

Each email unfortunately needs information about ip address , and we use ipinfo.io for that. So this is another additional blocking request.

Sometimes we also need to send push notification, so we are sending request to another external platform.

All in all there are few blocking requests, sometimes it runs smoothly, sometimes it takes much over 30 seconds depending on the network and API endpoints.

Fortunately for us all those actions are not necessary to return correct response to the application.

You've proposed using a queue, so I imagine adding stuff to databse queue table, and a cron running each minute? As far as I know 1 minute is the smallest value we can set for a cron on VPS servers. Standard hosting have more than 1 minute. Maybe we should use external tool for that like RabbitMq?

So in most pesimistic scenario user would need to wait for an email a minute or even more depending on server configuration and its possibilities.

Returning response and allowing script to continue would not create such delay as far as I understand, but I don't know how to achieve such functionality.

I hope I was clear enough. Maybe you could give me more hints about your queue idea?

_________________
I've created this great mobile app in Kinetise in less than an hour! Check it out:
https://www.kinetise.com/sed2015


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group