简体   繁体   English

504网关超时-PHP

[英]504 gateway timeout - php

I'm calling an api using file_get_contents which is rather sporadic, sometime the call returns data really quickly (1-2 seconds) at other times takes a bit longer (30 seconds plus) leading to a 504 gateway timeout, here is the header return: 我正在使用file_get_contents调用一个api,这是非常零星的,有时调用会非常快地(1-2秒)返回数据,而其他时候则需要更长的时间(超过30秒),导致504网关超时,这是标头返回:

"Array ( [0] => HTTP/1.1 504 GATEWAY_TIMEOUT [1] => Content-Length: 0 [2] => Connection: Close )” “数组([0] => HTTP / 1.1 504 GATEWAY_TIMEOUT [1] =>内容长度:0 [2] =>连接:关闭)”

I've tried setting - set_time_limit(0); 我尝试设置-set_time_limit(0); however this doesn't seem to have any effect, is there any other way to stop this timeout happening, ie wait longer to get a return from the api? 但这似乎没有任何效果,是否还有其他方法可以阻止此超时的发生,即等待更长的时间从api获得返回?

Cheers, 干杯,

Matt 马特

Regarding 504 error, either is php taking too long to process the script or your database process large query. 关于504错误,是php处理脚本花费的时间太长,还是数据库处理大型查询。 As discussed in comments, it seems like it is MySQL timeout. 正如评论中所讨论的,似乎是MySQL超时。

What you gonna do is to increase timeout in my.cnf (which is MySQL configurational file) and change this line of code wait_timeout to some reasonable value, lets say 28000. 您要做的是增加my.cnf(这是MySQL配置文件)中的超时并将该代码行wait_timeout更改为某个合理的值,比如说28000。

That should do it. 那应该做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM