Design: How to Solve 503 Error of API when Resources are not ava
- 时间:2020-09-08 11:19:41
- 分类:网络文摘
- 阅读:94 次
The HTTP 503 Error indidicates the server is busy. It might be due to the fact that the servers are overloaded (high load average).
One of my API is designed to return 503 Error when the cached file is not available. It is designed as the follows:
1 2 3 4 | if (!is_file($file)) { throw_503(); die(); } |
if (!is_file($file)) { throw_503(); die(); }
The $file will be updated periodically e.g. every minute via crontab. When the OS is writing to that file, the is_file will return false because the file is in-use.
One way of solving this is to have multiple caching versions, to avoid the single point of failure. For example, if a file-1 is not available we can check for file-2. These two files should not be updated at the same time.
Another way to resolve this issue is to add a delay check (hacky solution), for example:
1 2 3 4 5 6 7 | if (!is_file($file)) { sleep(1); // delay check. } if (!is_file($file)) { throw_503(); die(); } |
if (!is_file($file)) { sleep(1); // delay check. } if (!is_file($file)) { throw_503(); die(); }
–EOF (The Ultimate Computing & Technology Blog) —
推荐阅读:5 Ways to Develop a Better Email List Mosul Blogger Writes About The Horror Of Living Under ISIS Hijab-Wearing Blogger Becomes Newest Covergirl Ambassador High School Blogger Makes A Cameo In Election Coverage French Blogger Embarks On ‘Zero Waste’ World Tour 30 Incredibly Useful Tools You Need to Grow Your Blog What You Need to Know Before Becoming an Internet Entrepreneur Teen Horror Blogger Speaks Out About Killing Her Parents SEO for 2017: Post Penguin 4.0 and How to Take a Publisher’s App Trick Or Treat: How Businesses Are Cashing In On Halloween
- 评论列表
-
- 添加评论