WebFaction
Community site: login 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?

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 25 Sep '12, 13:09

pieterh
112
accept rate: 0%

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?

(25 Sep '12, 14:38) seanf

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?

(26 Sep '12, 02:16) pieterh

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.

(26 Sep '12, 03:54) todork

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.

(26 Sep '12, 04:41) pieterh

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.

(26 Sep '12, 05:05) todork

Ok, thanks.

(26 Sep '12, 05:43) pieterh
showing 5 of 6 show 1 more comments
Be the first one to answer this question!
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

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×265
×2
×1

question asked: 25 Sep '12, 13:09

question was seen: 3,829 times

last updated: 26 Sep '12, 05:43

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM