PycURL或任何其他python pakcage是否提供有关以下信息:
>查找
>连接时间
我想获得与此cURL命令相同的信息(无需使用子过程调用该命令):
命令
curl -s -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null https://stackoverflow.com/
输出:
Lookup time: 0.029
Connect time: 0.144
PreXfer time: 0.144
StartXfer time: 0.263
Total time: 0.803
解决方法:
是的,PyCurl提供了信息.您可以使用pycurl导出信息.它可以提供很多细节,而不仅仅是您提到的细节.
这是一个示例代码,可用于导出相同的信息:
import pycurl
from io import BytesIO
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://stackoverflow.com/')
c.setopt(c.WRITEDATA, buffer)
c.perform()
body = buffer.getvalue()
print('TOTAL_TIME: %f' % c.getinfo(c.TOTAL_TIME))
print('CONNECT_TIME: %f' % c.getinfo(c.CONNECT_TIME))
print('PRETRANSFER_TIME: %f' % c.getinfo(c.PRETRANSFER_TIME))
print('STARTTRANSFER_TIME: %f' % c.getinfo(c.STARTTRANSFER_TIME))
c.close()
结果如下:
TOTAL_TIME: 2.252639
CONNECT_TIME: 0.331571
PRETRANSFER_TIME: 0.331634
STARTTRANSFER_TIME: 0.638206
我发现GitHub link提到了一些其他标志,这些标志也可以在您的代码中使用.
以下是用于快速查看的标志:
* EFFECTIVE_URL
* HTTP_CODE
* TOTAL_TIME
* NAMELOOKUP_TIME
* CONNECT_TIME
* PRETRANSFER_TIME
* REDIRECT_TIME
* REDIRECT_COUNT
* SIZE_UPLOAD
* SIZE_DOWNLOAD
* SPEED_UPLOAD
* HEADER_SIZE
* REQUEST_SIZE
* CONTENT_LENGTH_DOWNLOAD
* CONTENT_LENGTH_UPLOAD
* CONTENT_TYPE
* RESPONSE_CODE
* SPEED_DOWNLOAD
* SSL_VERIFYRESULT
* INFO_FILETIME
* STARTTRANSFER_TIME
* REDIRECT_TIME
* REDIRECT_COUNT
* HTTP_CONNECTCODE
* HTTPAUTH_AVAIL
* PROXYAUTH_AVAIL
* OS_ERRNO
* NUM_CONNECTS
* SSL_ENGINES
* INFO_COOKIELIST
* LASTSOCKET
* FTP_ENTRY_PATH
标签:pycurl,dns,curl,performance-testing,python
来源: https://codeday.me/bug/20191028/1950706.html