dongnanman9093 2017-02-07 15:35
浏览 34
已采纳

如何在PHP脚本失败时避免服务器不响应

I can´t find an answer for this, probably I'm not searching with the right words.

When a PHP script fails (error in script, infinite loops, endless SQL calls, etc) the whole server goes "busy". It's like all the resources are taken and focus on trying to execute that script. By restarting apache/nginx the server goes back to normal.

How could this be avoided? Setting the timeout for the script won't solve it because if it's even 10 seconds timeout the server will be irresponsive for those 10 seconds to everybody.

Is there any way to avoid this happening? Yes, solving the script issues the problem will stop happening but I am sure there is a way to protect against this on the server side.

Just now an example comes to my mind. This script used to get the country code by calling a service in that website. For some reason the website would not serve to us randomly so the script would wait forever to receive the file contents.

$getcountry = file_get_contents('http://ip-api.com/php/'. getUserIP());

Thanks

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 如何在linux服务器做视频静态资源访问接口
      • ¥15 Python Xpath对<em>标签的爬取结果变成了- -(关键词-Xpath)
      • ¥15 el-cascader懒加载模式选中单选框加载下层无数据问题
      • ¥15 promql 参数怎么忽视大小写查询
      • ¥50 swift使用textkit读取大文本文件速度慢的问题
      • ¥20 统信linux360企业浏览器 如何配置扩展程序?(图形界面我知道)
      • ¥100 c/c++实现DoubleArrayTrie
      • ¥15 在开发/迭代一款企业信息软件时会耗费你们多长时间?
      • ¥15 如果可以为你提供一款定制化的企业软件,您最希望在哪个板块实现定制化?
      • ¥30 关于#网络安全#的问题:非对称加密验证