502 Bad Gateway on long running function

Hey so for quite some time I have been having issues on my website

We have a feature where you can import data from another website and this function usually takes some time the first time you run it, upwards to 3-4 minutes due to all the data coming in and the calculations needed to be made to correctly display it all.

But the problem is that when someone imports and their trade log (the data we read in) is really big, in the middle of it, maybe 60-75 seconds in it returns a 502 bad gateway.

Now I’m not sure how to fix this, I am running Laravel Forge and Laravel as the framework obviously.

In both PHP CLI and PHP FPM I set max_input_time = 3600 max_execution_time = 3600 ignore_user_abort = On

But neither of that fixed it. So I went to NGINX and set a bunch of variables to super high numbers but nothing fixed that either.

What can I do?

Here is what my nginx error log says: 2017/08/18 11:29:37 [error] 5104#5104: *552840 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:, server:, request: “GET /test1231 HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php/php7.1-fpm.sock:”, host: “

Here is PHP 7.1 FPM Log: [18-Aug-2017 11:29:37] WARNING: [pool www] child 1326, script ‘/home/forge/’ (request: “GET /index.php”) execution timed out (78.546796 sec), terminating

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Were you able to resolve this problem? I am having the same issue. Using Laravel Forge (nginx PHP7) and getting the same error on long running scripts. I haven’t been able to find a solution.