I've encountered http 504 gateway timeout error for several times when I was trying to call a GET API that was programmed by PHP.
Here is my server and AWS environment.
From some articles about 504 gateway timeout, I've already tried to modify these settings:
# ELB
idle timeout => 300
# php.ini
max_execution_time => 301
max_input_time => 301
# httpd conf
MaxKeepAliveRequests => 100
KeepAliveTimeout => 30
But all of them are not helpful for me, it's still get 504 gateway timeout sometimes.
My php script is not a long script, it just get data from mysql database (AWS RDS) from 3 tables and return data to client, no uploading file or generateing big file, so I think the execution time is not the problem.
The strange thing is that 504 gateway timeout error is not always happened, most of time it is normal, just happened SOMETIMES, for now, I still don't understand when 504 error will happen, it's really strange, if anyone can give me some suggestions about how to resolve this problem, it's really a big favor for me.
=== New Update ===
I've just found a problem in my php code, I thought that's namespace with autoload problem.
I have 2 php files in the same folder, it means 2 classes with the same namespace
files:
My/Namespace
- Class1.php
- Class2.php
Class and namespace:
Class1
// Class1
namespace My\Namespace;
class Class1 {
public static function getInstance() {
//return...
}
}
Class2
// Class2
namespace My\Namespace;
class Class2 {
public static function getInstance() {
//return...
}
public function getClass1Instance() {
$class1 = Class1::getInstance();
return $class1;
}
}
In Class2.php I try to call Class1's static function, but I didn't add "use namespace", so I add the following line to Class2.php
use My\Namespace\Class1;
Problem was solved! But I still not really sure why I should add "use namespace" to Class2.php, Class1 and Class2 are both in the same namespace, should I add "use namespace" even through they are in the same namespace?
p.s. I found this namespace problem because when 504 gateway error happened, I tried to call the API many times in a short period, and the php error message show up and tell me
"Class1 is not found in Class2.php"
but sometimes php error message show
"Cannot call a overloaded function in Class2.php, getClass1Instance()"
Wish I provide enough message about this question, and thanks for everyone who left comment or answered my question, m(_ _)m
I suggest you take a look at the Health Check of ELB.
Health Check is a source of seemingly-random 504 errors when it is not properly configured. When the ELB thinks your server is not 'healthy' then ELB answers 504 to the end user, and that 504 error is not logged anywhere in your PHP environment because it was generated in the ELB.
See http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/ts-elb-healthcheck.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With