curl命令的超時時間

轉載自:http://blog.chinaunix.net/uid-20788470-id-1841681.html php


今天在一臺服務器上忽然看到一個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/nullhtml

按理來講, 應該是5s就會超時退出了!  納悶之餘想起wget好像對超時時間, 是有分階段的, 好比說請求的超時, 傳輸的超時等等, 因此就仔細查看了下curl的手冊頁:
服務器

原來使用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.ide

這個是指定鏈接超時時間。 若是出錯, 提示形如:curl: (28) connect() timed out!ui

 

-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.this

這個是指定整個過程最大的容許時間。 出錯提示如:curl: (28) Operation timed out after 2000 milliseconds with 0 bytes receivedurl


 

還能夠這樣用: curl -o x.log "http://www.yyyy.com" --speed-time 5 --speed-limit 1
是說將url內容保存到x.log中, 若是傳輸速度小於1字節/秒的狀態持續5秒,該鏈接就會終止.spa

相關文章
相關標籤/搜索