login community faq

I've got a import function for one of my apps, and it worked great (with another host and my localhost), but on Webfaction it's not working.

Due to the executiontime of nearly 15 minutes, I want to quit the request, give the user a 'busy with importing' message and continue the script in the background. On my localhost (and on a place hosted somewhere else) it works fine. On Webfaction the page keeps loading (for about 10 minutes) and after that gives a server error: Error: 504 Gateway Timeout.

What can be the problem and how can I fix this?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
header("Location: ".$url); // redirect the url to the 'busy importing' page
ob_end_clean(); //Erase the output buffer
header("Connection: close"); //Tell the browser that the connection's closed
ignore_user_abort(true); //Ignore the user's abort (which we caused with the redirect).
set_time_limit(0); //Extend time limit
ob_start(); //Start output buffering again
header("Content-Length: 0"); //Tell the browser we're serious... there's really nothing else to receive from this page.
ob_end_flush(); //Send the output buffer and turn output buffering off.
flush(); //Yes... flush again.
session_write_close(); //Close the session.

asked Sep 25 '12 at 13:09

pieterh's gravatar image

pieterh
11

I just tried this with a test account on your server and had the same problem that you described. What sort of PHP deployment are you using on your other hosts - mod_php, CGI, FastCGI, something else?

(Sep 25 '12 at 14:38) seanf ♦♦ seanf's gravatar image

On my localhost I use WAMP (so that could react differently). The server I used for testing is a server of AppFog. They also use appache and Linux, but they have some kind of accelerator installed.

The code above works on both, but is also working on lots of other servers. See http://stackoverflow.com/questions/10504753/can-i-cause-a-redirect-to-occur-before-my-php-script-finishes

It looks like webfaction uses software to keep the connection open or something? Or does add something to the content so the content-length is not 0?

I also found other people for who this script is not working: http://stackoverflow.com/questions/11818702/php-redirect-user-and-continue-process-script

Do you have any clue?

(Sep 26 '12 at 02:16) pieterh pieterh's gravatar image

Hi,

I wasn't able to make this code work properly on our servers, using PHP 5.2, 5.3, 5.4 both via CGI and FastCGI.

I'd also suggest looking at this post on StackOverFlow.

(Sep 26 '12 at 03:54) todork todork's gravatar image

I can try one of the libraries for queueing, but it seems a little bit exorbitant for what I'm trying to do.

One of the solutions in the stackoverflow post you are linking to is exactly what I want to do. But that's the thing that's not working.

Another, perhaps simpler, approach is to use ignore_user_abort - once you've sent the page to the user, you can do your final processing without fear of premature termination, though this does have the effect of appearing to prolong the page load from the user perspective.

(Sep 26 '12 at 04:41) pieterh pieterh's gravatar image

I don't know why it doesn't work on our servers - perhaps it only works when PHP is installed as an Apache module. You can try installing a local instance of Apache with mod_php in your account if you want to test this possibility.

(Sep 26 '12 at 05:05) todork todork's gravatar image

Ok, thanks.

(Sep 26 '12 at 05:43) pieterh pieterh's gravatar image
showing 5 of 6 show all
Be the first one to answer this question!
If you have an answer to the above question, then use the form below. Otherwise, use the appropriate 'add new comment' button above to post your feedback.
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×146
×1
×1

Asked: Sep 25 '12 at 13:09

Seen: 370 times

Last updated: Sep 26 '12 at 05:43

Plans & prices    Sign up    Why WebFaction?    Contact us    Affiliate program    Support    Legal    Jobs    Blog    Control panel login
Powered by OSQA
© Copyright 2003-2012 Swarma Limited - WebFaction is a service of Swarma Limited