Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I got a 504 error in 10 minutes of script work #12

Open
bicdibuss opened this issue May 23, 2018 · 9 comments
Open

I got a 504 error in 10 minutes of script work #12

bicdibuss opened this issue May 23, 2018 · 9 comments

Comments

@bicdibuss
Copy link

I have a php5.6 nginx 2GB Ram on my server. On localhost it works good. What the problem can it be?

@ionurboz
Copy link

ionurboz commented May 23, 2018

Are you more open-minded than you mean?

@mitchobrian
Copy link

@ionurboz :)
@bicdibuss maybe Same-Origin-Policy ?

@bicdibuss
Copy link
Author

Im building a chat using this script on localhost all works good, but when I moove scrips to the server it works only about 10 minutes then in console of browser I see 504 error and script stop work. After reloading page it works again the same time.

@ionurboz
Copy link

What your application name? Maybe the localhost application blocked more live connection?

@bicdibuss
Copy link
Author

On localhost it works good. On server even example script got error. May be I need some configs of nginx or php?

@ionurboz
Copy link

ionurboz commented May 24, 2018

Maybe this is the root of the problem max_execution_time.

php.ini edit max_execution_time.

Defaults:

max_execution_time | "30"

try repeating the same things 30 seconds later without refreshing the page

if you do not find a solution usleep (); investigate

@bicdibuss
Copy link
Author

I have set max_execution_time=3600 but it dosent help
server.php?timestamp=1527239428 504 (Gateway Time-out)

@panique
Copy link
Owner

panique commented May 25, 2018

it's probably a 600 seconds limit on nginx side :)

@sunnz
Copy link

sunnz commented Mar 1, 2020

I am getting 504 error from nginx too when it reaches its time limit on how long it would wait for a response from php-fpm.

What's the best practice?

For now I put a time limit into the PHP script, so it would return a json object before the nginx time limit kicks in, then javascript would send another request to the server.

IE

$start_time = time();
$time_limit = 60; // set this to be less than the nginx time limit
// main loop
while (true) {
    ...
    $time_lapsed = time() - $start_time;
    if ($time_lapsed >= $time_limit || $last_ajax_call == null || $last_change_in_data_file > $last_ajax_call) {
        ...
        // leave this loop step
        break;
        ...

By doing this it is combining short-polling and long-polling... but not much choice when you can't control nginx limits from PHP I guess?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants