curl的超时参数
公司生产中Ocr服务器经常无响应,需要监控进程立即重启,但是利用curl的监控脚本指定--connect-timeout参数似乎总不能发挥作用,查阅文档:
今天在一台服务器上突然看到一个curl进程已经运行了28天还木结束, 有点奇怪! 我在使用curl的时候也设置了超时时间, --connect-timeout 5
curl --connect-timeout 5 --data-binary "set=${L_UPLOAD_DATA_ENCODED}" http://172.88.99.00:8080/xxx.php &>/dev/null
curl --connect-timeout 5 --data-binary "set=${L_UPLOAD_DATA_ENCODED}" http://172.88.99.00:8080/xxx.php &>/dev/null
按理来说, 应该是5s就会超时退出了! 纳闷之余想起wget好像对超时时间, 是有分阶段的, 比如说请求的超时, 传输的超时等等, 所以就仔细查看了下curl的手册页:
原来使用curl时,有两个超时时间:一个是连接超时时间,另一个是整个过程允许的最大时间,
--connect-timeout <seconds>
Maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once curl has connected this option is of no more use. See also the -m/--max-time option.
If this option is used several times, the last one will be used.
Maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once curl has connected this option is of no more use. See also the -m/--max-time option.
If this option is used several times, the last one will be used.
这个是指定连接超时时间。 如果出错, 提示形如:curl: (28) connect() timed out!
-m/--max-time <seconds>
Maximum time in seconds that you allow the whole operation to take. This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going down. See also the --connect-timeout option.
If this option is used several times, the last one will be used.
Maximum time in seconds that you allow the whole operation to take. This is useful for preventing your batch jobs from hanging for hours due to slow networks or links going down. See also the --connect-timeout option.
If this option is used several times, the last one will be used.
这个是指定最大的允许时间。 出错提示如:curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received
还可以这样用: curl -o x.log "http://www.yyyy.com" --speed-time 5 --speed-limit 1
是说将url内容保存到x.log中, 如果传输速度小于1字节/秒的状态持续5秒,该连接就会终止.
是说将url内容保存到x.log中, 如果传输速度小于1字节/秒的状态持续5秒,该连接就会终止.
使用curl时,有两个超时时间:一个是连接超时时间,另一个是数据传输的最大允许时间。
连接超时时间用 --connect-timeout 参数来指定,数据传输的最大允许时间用 -m 参数来指定。
例如:
curl --connect-timeout 10 -m 20 "http://XXXXXXX"
连接超时的话,出错提示形如:
curl: (28) connect() timed out!
数据传输的最大允许时间超时的话,出错提示形如:
curl: (28) Operation timed out after 2000 milliseconds with 0 bytes received
分类:
Production
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律