问题原文
原帖链接 · web-tiki · CC BY-SA 3.0
I am running a php script on a website that creates thumbnails from a big image. The script uses imagick to generates 10 thumbnails per image.
It runs on first page load, when the thumbnails don't exist yet and can potentially be asked to generate hundreds of thumbnails on first page load. This takes time (about 2.5 seconds per batch of 10 thumbnails) and therefore the server returns a 504 Gateway Timeout error.
This error means:
The server, while acting as a gateway or proxy, did not receive a timely response from the upstream server specified by the URI... [ source ]
Which I can understand as the php script can be running for 60 seconds or more.
My question is : does this mean that the script has crashed the server and that it has stoppped during it's execution?
Or does this just mean that my browser is to impatient to wait for the server response?
My main concern is that the script craches during the thumbnail generation and can potentialy generate corrupted files.
已采纳解答
原帖链接 · Stephen Ostermiller · CC BY-SA 3.0
A Gateway Timeout error does not usually mean that your server crashed. Neither do browsers generate these errors. It means that an intermediate server got tired of waiting for your primary server.
When you get these errors, it usually means that there is a proxy server involved. You might have a reverse proxy from one port to another. You might be using a CDN or a load balancer.
You should be worried about corrupt files. Generating files on first load is not usually a good plan. Most requests to have a time limit before the web server kills off the process. For example if you are kicking this process off through PHP, you would need to set a long enough http://php.net/manual/en/function.set-time-limit.php
There is also a race condition that you have to consider. What happens when a second request comes in while the first is still processing? Does it also generate images? Two processes trying to write images to the same locations can cause corruption.
Jobs that take more than a few seconds should be handled differently. You have a few options. You could run them asynchronously and have web requests check the status. You could resize the images after they are uploaded, or as part of the website deployment. You could have a cron job that periodically checks to see if images need to be resized.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
