问题原文
原帖链接 · HOY · CC BY-SA 4.0
I am on a shared server (Siteground), and since my WordPress PHP script takes more than 30 seconds, it returns a 504 Gateway timeout.
Will my query run and complete if it doesn't encounter a further error?
Edit: I asked why I received this error to my hosting team, here the Siteground Hosting expert explained the issue as follows:
We use both Apache + Nginx on all our servers. Apache is used for main web service, while the Nginx is used as a reverse-proxy and distribute cache. When the response cannot be served from cache (usually this refers to dynamic content) a request from Nginx is done towards Apache. This when Apache is processing the request, forwards it to your website and according to the PHP logic MySQL queries can be done or other data fetched. When this process takes too long and Apache does not return the response in a timely manner to Nginx you will see this error. In short Apache cannot server the request since the application did completed the process within the allowed time. This also means that the initiated process most probably did not completed fully and some data / actions might have been saved / executed.
The expert says that "initiated process most probably not completed fully",
More Details on my scenario: My script adds woocommerce products with variations using wp_insert_post method to my wordpress website. After products added, it displays the images of newly added products.
When I add 1 product (40 variations), it completes and displays the product image. When I add 6 products (240 variations), I receive error directly in my browser.
So to further test this issue, I modified my code and re-wrote it using ajax and added a process bar like system. (Which increments a number for each variation).
After I run the code for 1 product (with 40 variations), the process number increases to 40, and it displays the product image.
When I run my code for 6 product, the process number increases to 240, but it doesn't display anything, and when I check, it receives an 504 error. (jQuery.Ajax function error section)
So this makes me think that the query runs even it timeouts, but still I am not able to be sure, and looking for details behing 504 gateway timeout error since there are no good documentation on this.
社区高分解答
原帖链接 · Sakura Kinomoto · CC BY-SA 4.0
Script will not stop executing until they reach php timeout itself.
The 504 error are generated on the gateway / proxy itself, it's not coming from the php process.
It's because this, if you have an Apache with Apache-mod-php you will never receive this error, because there's not a proxy.
Extending the explanation, think as follows:
You have a PHP process. The PHP process can be a PHP-FPM, PHP-CGI, or Apache-MOD-PHP. On this process, you have a timeout (configured on php.ini or with a ini_set).
The PHP proxy gives a response in the allowed time (aka: if you have a set_time_limit(600), your PHP process can be running up to 10 minutes).
Without relation on this sentence, you can have another process waiting for these response: That's the case of a apache (configured to contact to php by cgi or fpm), a nginx, a lighthttpd, and others. That's not the case of a apache configured by apache-mod-php. This second process, have a new timeout (proxy_timeout), configured on the vhost / general server app config. That's the time the program will wait for a response from PHP processing engine.
The last sentence, can be repeated on each proxy / gateway.
Think on this scenario:
haproxy (Timeout 1) --> Nginx (Frontend / cache) (Timeout 2) --> Apache (Timeout 3) -> PHP-FPM (PHP Timeout / set_time_limit).
And a very simple scenario:
Apache (with apache-mod-php) (PHP Timeout / set_time_limit).
Each timeout appearance (except the PHP Timeout itself) is a probable origin of a 504 HTTP gateway timeout error.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
