PHP curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) too slow

Active3 hr before
Viewed126 times

6 Answers


To properly track down the problem, I would recommend you use the curl command line tool and its --trace-ascii and --trace-time options to see what seems to take time. You may need to snoop on the network with wireshark or similar to get an even better picture of what's going on., Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Ignoring to check the certificate should be very fast and not be measurable compared to how long the rest of the SSL handshake procedure takes.,I use this method to get facebook api data. just a search query. but I find use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); cost more time during a curl time (over 10+ seconds).

To keep all the information in one place: In your code, you should write the following:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/crt/file.crt');

true to disable the progress meter for cURL transfers. , The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY. ,curl_setopt — Set an option for a cURL transfer, Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.

load more v

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. ,Following is the CURL_GETINFO array,How can I speed up the CURL processing time?,Following is the curl code

Following is the curl code

    $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);


    if ($devnull) {
load more v

More info about curl_multi_init() you can see on,Use curl_multi_init():,For your problem, you just need to put a new input for the tokens and add one param on curl request.,I build the following script to like a facebook status using tokens the problem is the execution take too much time for 5 tokens it take >= 10 seconds

I build the following script to like a facebook status using tokens the problem is the execution take too much time for 5 tokens it take >= 10 seconds

foreach($tokens as $token)

   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, '');
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_VERBOSE, true);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0;    en-US; rv:1.0) Gecko/25250101');
   curl_setopt($ch, CURLOPT_POSTFIELDS, array('access_token' => $token));
load more v

First, POST and GET merge   curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, false);   curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, false); The second POST and GET are separated POST   curl_setopt($ch, CURLOPT_SS...

    public function get_cookie(){
        $ch =curl_init();
        curl_setopt($ch,CURLOPT_URL,'Crawl URL');
        $header = array();
                 curl_setopt($ch,CURLOPT_COOKIE,'cookie value to be set');
        $content = curl_exec($ch);
        echo "<pre>";print_r(curl_error($ch));echo "</pre>";
        echo "<pre>";print_r(curl_getinfo($ch));echo "</pre>";
        echo "<pre>";print_r($header);echo "</pre>";
        echo "</br>",$content;

So I decided to get this data using curl in php. I've copied the GET HTTP request to download link with headers and got the data. But the whole magic is in session/cookies which I can just copy from existing session. So to make curl query succeed I have to:,Flurry allows to download raw event data in csv format on Event Logs page, so I decided to import all the events and analyze them at home. ,This is how I successfully logged in to Flurry:,You need to add the Curl libraries to the command line PHP.ini.

Here's the code:

    $cookie_file_path = "cookies.txt";
    $LOGINURL = "";
    $MY_EMAIL = "my email";
    $MY_PASS = "password";
    $MY_GAME_ID = "gameid";

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/");
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
    curl_setopt($ch, CURLOPT_REFERER, $LOGINURL);

    curl_setopt($ch, CURLOPT_URL, $LOGINURL);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "loginEmail=$MY_EMAIL&loginPassword=$MY_PASS&__checkbox_rememberMe=true&");

    $result = curl_exec($ch);

    $remotePageUrl = "$MY_GAME_ID&versionCut=versionsAll&intervalCut=7Days&stream=true&direction=1&offset=0";
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_URL, $remotePageUrl);
    $result = curl_exec($ch);

    echo $result;

Also tried to pass cookies (like it does from browser), but nothing helped:

Cookie: _ga = GA1 .2 .100867533 .1424333566;
S0hZTkM0RFRXRjJNSlg2TVdXSEs_fit = 1424333594147;
fid = SG1162A8DEFC14B8428E7C2AFC71D3AEA00C1872F5;
JSESSIONID = w34~mvbdvftm9x9dez9dg9b2pmhs;
_map_zoomLevel = 0;
_map_zoneId = 0;
__utmt = 1;
__utmt_~1 = 1;
S0hZTkM0RFRXRjJNSlg2TVdXSEs_fs = eyJiYSI6MTQyNDMzNzkzMzU2OCwicGF1c2VUaW1lc3RhbXAiOjAsImJjIjotMSwiZXZlbnRDb3VudGVyIjowLCJwdXJjaGFzZUNvdW50ZXIiOjAsImVycm9yQ291bnRlciI6MCwidGltZWRFdmVudHMiOltdfQ == ;
__utma = 83277827.100867533 .1424333566 .1424333594 .1424336847 .2;
__utmb = 83277827.8 .10 .1424336847;
__utmc = 83277827;
__utmz = 83277827.1424333594 .1 .1.utmcsr = | utmccn = (referral) | utmcmd = referral | utmcct = /; __utma=34058230.100867533.1424333566.1424333566.1424336847.2; __utmb=34058230.8.10.1424336847; __utmc=34058230; __utmz=34058230.1424333566.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _mkto_trk=id:802-TBR-126&; S0hZTkM0RFRXRjJNSlg2TVdXSEs_flp=1424338032448
load more v

Other "undefined-undefined" queries related to "PHP curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false) too slow"