ARTICLE AD BOX
new to this. I'm looking to measure the TTFB of an http proxy to an endpoint, but having a hard time figuring out if my code is fetching those speeds accurately.
My goal is to maximize accuracy while keeping it efficient preventing it from burning residential ip data. I'm unsure how I can use pyCurl to strictly receive 1 byte of data or prevent it from downloading the full page so i opted into using:
c.setopt(c.NOBODY, 1)If there is any work around and I can use get instead, please post! Or if there is no difference then let me know that too!
If I can further optimize and improve my code from consuming data, please post suggestions as well!
The full code as it reads (intentionally left the proxy and url endpoint out for demonstration purposes):
import json import pycurl import certifi header = ["Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7, User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36, Accept-Encoding: gzip, deflate, br, zstd"] c = pycurl.Curl() c.setopt(c.URL, URL) c.setopt(c.HTTPHEADER, header) c.setopt(c.PROXY, proxy) c.setopt(c.PROXY_CAINFO, certifi.where()) c.setopt(c.HTTP_VERSION, c.CURL_HTTP_VERSION_2_0) c.setopt(c.NOBODY, 1) c.perform() ttfb = c.getinfo(c.STARTTRANSFER_TIME) c.close() data = json.dumps({ "ttfb": ttfb*1000, }) print(data)