2010-01-21 96 views
1

我有一个PHP CURL请求到一个HTTPS站点,它接受一个JSON和请求并返回一个JSON响应。通常不会超过1秒钟。但是,我已经看到CURL响应时间是可变的。有时需要4秒才能回复,有时需要1.2秒。为什么会这样?我如何才能更快速地处理整个请求?变量CURL响应时间

以下是卷曲的响应时间在3个不同时间相同的请求..

Array 
(
    [url] => https://xx.xx.xxx.xx/site/y 
    [content_type] => application/json 
    [http_code] => 200 
    [header_size] => 198 
    [request_size] => 358 
    [filetime] => -1 
    [ssl_verify_result] => 20 
    [redirect_count] => 0 
    [total_time] => 4.213941 
    [namelookup_time] => 2.1E-5 
    [connect_time] => 0.015284 
    [pretransfer_time] => 0.722955 
    [size_upload] => 222 
    [size_download] => 553 
    [speed_download] => 131 
    [speed_upload] => 52 
    [download_content_length] => 0 
    [upload_content_length] => 0 
    [starttransfer_time] => 4.015112 
    [redirect_time] => 0 
) 


Array 
(
    [url] => https://xx.xx.xxx.xx/site/y 
    [content_type] => application/json 
    [http_code] => 200 
    [header_size] => 198 
    [request_size] => 358 
    [filetime] => -1 
    [ssl_verify_result] => 20 
    [redirect_count] => 0 
    [total_time] => 1.27581 
    [namelookup_time] => 8.3E-5 
    [connect_time] => 0.016223 
    [pretransfer_time] => 0.104996 
    [size_upload] => 222 
    [size_download] => 553 
    [speed_download] => 433 
    [speed_upload] => 174 
    [download_content_length] => 0 
    [upload_content_length] => 0 
    [starttransfer_time] => 1.273922 
    [redirect_time] => 0 
) 

Array 
(
    [url] => https://xx.xx.xxx.xx/site/y 
    [content_type] => application/json 
    [http_code] => 200 
    [header_size] => 198 
    [request_size] => 358 
    [filetime] => -1 
    [ssl_verify_result] => 20 
    [redirect_count] => 0 
    [total_time] => 1.294147 
    [namelookup_time] => 7.0E-5 
    [connect_time] => 0.025723 
    [pretransfer_time] => 0.123456 
    [size_upload] => 222 
    [size_download] => 553 
    [speed_download] => 427 
    [speed_upload] => 171 
    [download_content_length] => 0 
    [upload_content_length] => 0 
    [starttransfer_time] => 1.292577 
    [redirect_time] => 0 
) 
+1

这不取决于网站的速度有多快,与卷曲无关吗? – 2010-01-21 18:06:33

+0

这确实是一个问题,让你要求更快的网站回应,而不是更快的回应。 – 2010-01-21 18:08:20

+0

您是否尝试过使用浏览器访问“https:// xx.xx.xxx.xx/site/y'并查看需要多长时间?另外,响应数据变化很大吗?如果没有,缓存可能是一个选项。 – 2010-01-21 18:15:38

回答

1

还有什么是该网站在做什么?如果它有固定数量的线程(比如说),并且每个线程都很忙,那么你的请求将不得不等待一个线程来处理它。如果没有线程忙,那么它会立即被服务。

当然,最简单的情况是服务器CPU具有有限的资源并提供不确定数量的请求,但没有服务保证。

+0

这种说法是有道理的。如果网站正在接受JSON请求,处理它一秒钟,并返回响应,为什么会有可变的卷曲时间。我不确定网站是否正在进行多线程。 – Jake 2010-01-21 18:14:15

0

CURL是在PHP中进行HTTP请求的最佳方式。这几乎肯定是需要时间的服务。喜欢在熟食店排队等候三明治。如果服务速度不在您的手中,并且您没有其他可供选择的服务,那么最好的办法就是确保您的页面上的其他内容在请求发出时继续加载。