大网数据广告活动
网站运营与故障问答

Does a 504 Gateway Timeout error mean a server has crached?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-03-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。