Skip to content

Getting 504 Gateway Time-out on Lightsail IIS running PHP scripts

0

I have on PHP script that can run over 1 minute. I've adjusted PHP timeouts, I adjusted IIS ApplicationPool Process Model Shutdown Timeout, I adjusted Website Advanced Settings Limits Connection Timeout-out and still my script only runs for about 1 min and then gets the 504 Gateway time-out.

What other timeout parameter do I need to increase so my PHP script can run longer than 1 minute?

  • For now, I've moved this particular PHP script to my alternate hosting site where it does not time out after 1 min. As additional information, I'm using an AWS loadbalancer to manage the SSL. I don't see any sort of timeout setting for the loadbalancer.

    I don't want to use my alternate hosting site long term so I still am looking for the time-out setting that is causing my problem.

asked 2 years ago362 views

4 Answers
0
Accepted Answer

I found a much faster (and cheaper) API for this script hosted in this country instead of Europe. So far, the 1 min. limit has not affected the script since it now runs so much faster.

For now, I'll mark this case RESOLVED

answered 2 years ago

0

Hello.

Is PHP being called from FastCGI?
In that case, I think it would be a good idea to try extending the timeout on the FastCGI side as shown in the answer at the URL below.
https://learn.microsoft.com/en-us/answers/questions/854979/the-fastcgi-process-exceeded-configured-activity-t

EXPERT

answered 2 years ago

  • I changed FastCGI Request Timeout from 90 to 360 seconds and restarted IIS. Script still gets Time-Out error after around 1 min.

0

Can you load a php page with phpinfo(); to verify PHP timeout settings?

Verify max-execution-time value is changed from default 30 seconds.

AWS
EXPERT

answered 2 years ago

  • Phpinfo shows max execution set to 1000 and php script still gets Time-out error after about 1 min.

0

When encountering a 504 Gateway Time-out error on a Lightsail instance running IIS with PHP scripts, there are several timeout settings you need to consider beyond just the PHP and IIS configurations you've already adjusted.

One important aspect to consider is the connection tracking timeout on the EC2 instance that powers your Lightsail server. Amazon EC2 has introduced configurable idle timeouts for connection tracking, which can affect long-running processes like your PHP script.

For TCP connections, which are likely used by your web server, the default idle timeout for established connections can be up to five days. However, this may be affected by other networking components in your architecture, such as load balancers or firewalls, which typically have TCP established idle timeouts in the range of 60 to 90 minutes.

To address this, you might want to adjust the connection tracking idle timeout on your Lightsail instance to match your needs. This can be done at the Elastic Network Interface (ENI) level attached to your instance.

Additionally, if your PHP script is making API calls or interacting with other AWS services, you should check the timeout settings for those services as well. For example, if you're using AWS IoT, there's a configurable timeout called inProgressTimeoutInMinutes that can be set for job executions.

Lastly, while not directly related to Lightsail, it's worth noting that if you were using API Gateway with Lambda, you would need to ensure both the API Gateway and Lambda timeout settings are configured correctly to allow for longer-running scripts.

In summary, to allow your PHP script to run longer than 1 minute:

  1. Check and adjust the connection tracking idle timeout on your Lightsail instance's ENI.
  2. Ensure any AWS services your script interacts with have appropriate timeout settings.
  3. Review your entire network architecture for any components that might be enforcing shorter timeouts.
  4. Consider optimizing your PHP script to reduce execution time if possible.

If after adjusting these settings you still experience timeouts, you may need to contact AWS support for further assistance, as there could be Lightsail-specific limitations or configurations that need to be addressed.

Sources
Introducing configurable Idle timeout for Connection tracking | Networking & Content Delivery
TimeoutConfig - AWS IoT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.