本文介绍了用PHP进行CURL-非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我必须请求一个返回JSON请求的URL.我正在使用PHP和CURL来做到这一点.当前,请求和响应大约需要3-4秒.

I have to request a URL which returns a JSON request. I am using PHP and CURL to do this. Currently it takes around 3-4 seconds for the request and response.

以下是卷曲代码

    $ch = curl_init();
    $devnull = fopen('/tmp/curlcookie.txt', 'w');

    curl_setopt($ch, CURLOPT_STDERR, $devnull);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $desturl);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

    $ret = curl_exec($ch);

    curl_close($ch);

    if ($devnull)
    {
        fclose($devnull);
    }

以下是CURL_GETINFO数组

Following is the CURL_GETINFO array

Array
(
    [url] => https://xx.xx.xxx.xx/portalsite/tester
    [content_type] => application/json
    [http_code] => 200
    [header_size] => 198
    [request_size] => 835
    [filetime] => -1
    [ssl_verify_result] => 20
    [redirect_count] => 0
    [total_time] => 2.054561
    [namelookup_time] => 6.5E-5
    [connect_time] => 0.016048
    [pretransfer_time] => 0.123947
    [size_upload] => 699
    [size_download] => 46735
    [speed_download] => 22746
    [speed_upload] => 340
    [download_content_length] => 0
    [upload_content_length] => 0
    [starttransfer_time] => 1.743973
    [redirect_time] => 0
)

如何加快CURL的处理时间?

How can I speed up the CURL processing time?

谢谢

推荐答案

看起来大多数时候都在等待服务器响应(starttransfer_time-pretransfer_time = 1.620026)...也许服务器正在做一些数据库或其他操作操作需要时间吗?

it looks like most of the time is waiting for the server to respond (starttransfer_time - pretransfer_time = 1.620026)... maybe the server is doing some database or other operation that takes time?

这篇关于用PHP进行CURL-非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 00:35