公司生產中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