cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

cURL PHP Taking Too Long On POST

From: Brian Wilkins <brian_at_hcc.net>
Date: Sat, 25 Sep 2004 19:00:40 +0600

Hi,
   I have a PHP script (detailed below), which takes very long to POST to the
server. For each request, it takes at least 5 seconds to process the cURL
request, then almost 7 seconds to receive a response. Any clue on why this is
happening? I have posted a copy of the log of the request below, along with
the code.

-- LOG --

49:1 - Beginning of dispatch.cgi
49:1 - Inside of dispatch.cgi
49:1 - dispatch.cgi Connect to server
49:2 - Beginning of bal2.cgi - DC#DC046803629
49:2 - End of bal2.cgi - DC#1426875816
49:2 - dispatch.cgi Got response from server
49:02 - End of CURL
49:02 - Just after succeeded
49:02 - Return from CURL, end of function connect(bal2, DC046803629, )
49:02 - Call to function connect(bal2, DC046803631, )
49:02 - Just after curl_init()
49:02 - Beginning of CURL
49:7 - Beginning of dispatch.cgi
49:7 - Inside of dispatch.cgi
49:7 - dispatch.cgi Connect to server
49:7 - Beginning of bal2.cgi - DC#DC046803631
49:7 - End of bal2.cgi - DC#5431885316
49:7 - dispatch.cgi Got response from server
49:07 - End of CURL
49:07 - Just after succeeded
49:07 - Return from CURL, end of function connect(bal2, DC046803631, )
49:07 - Call to function connect(bal2, DC046803632, )
49:07 - Just after curl_init()
49:07 - Beginning of CURL
49:12 - Beginning of dispatch.cgi
49:12 - Inside of dispatch.cgi
49:12 - dispatch.cgi Connect to server
49:13 - Beginning of bal2.cgi - DC#DC046803632
49:13 - End of bal2.cgi - DC#7929743938
49:13 - dispatch.cgi Got response from server
49:13 - End of CURL
49:13 - Just after succeeded
49:13 - Return from CURL, end of function connect(bal2, DC046803632, )
49:13 - Call to function connect(bal2, DC046822311, )
49:13 - Just after curl_init()
49:13 - Beginning of CURL
49:18 - Beginning of dispatch.cgi
49:18 - Inside of dispatch.cgi
49:18 - dispatch.cgi Connect to server
49:18 - Beginning of bal2.cgi - DC#DC046822311
49:18 - End of bal2.cgi - DC#1254447719
49:18 - dispatch.cgi Got response from server
49:18 - End of CURL
49:18 - Just after succeeded
49:18 - Return from CURL, end of function connect(bal2, DC046822311, )
49:18 - Call to function connect(bal2, DC046822312, )
49:18 - Just after curl_init()
49:18 - Beginning of CURL
49:24 - Beginning of dispatch.cgi
49:24 - Inside of dispatch.cgi
49:24 - dispatch.cgi Connect to server
49:24 - Beginning of bal2.cgi - DC#DC046822312
49:24 - End of bal2.cgi - DC#0425485759
49:24 - dispatch.cgi Got response from server
49:24 - End of CURL
49:24 - Just after succeeded
49:24 - Return from CURL, end of function connect(bal2, DC046822312, )
49:24 - Call to function connect(bal2, DC046822313, )
49:24 - Just after curl_init()
49:24 - Beginning of CURL
49:29 - Beginning of dispatch.cgi
49:29 - Inside of dispatch.cgi
49:29 - dispatch.cgi Connect to server
49:30 - Beginning of bal2.cgi - DC#DC046822313
49:30 - End of bal2.cgi - DC#0162757434
49:30 - dispatch.cgi Got response from server
49:30 - End of CURL
49:30 - Just after succeeded
49:30 - Return from CURL, end of function connect(bal2, DC046822313, )
49:30 - Call to function connect(bal2, DC046822315, )
49:30 - Just after curl_init()
49:30 - Beginning of CURL
49:35 - Beginning of dispatch.cgi
49:35 - Inside of dispatch.cgi
49:35 - dispatch.cgi Connect to server
49:35 - Beginning of bal2.cgi - DC#DC046822315
49:35 - End of bal2.cgi - DC#9540396670
49:35 - dispatch.cgi Got response from server
49:35 - End of CURL
49:35 - Just after succeeded
49:35 - Return from CURL, end of function connect(bal2, DC046822315, )

-- END LOG --

-- START CODE --

/****************
* Connect *
****************/

function connect($Service, $DC_NUM, $MoreData)
{
        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - Call to function connect($Service, $DC_NUM,
$MoreData)\n";
        $fp = fopen("/var/log/mundotel/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        $vars = "Service=$Service&PIN=$DC_NUM&$MoreData";

        $ch = curl_init();

        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - Just after curl_init()\n";
        $fp = fopen("/var/log/ourwebsite/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        curl_setopt($ch, CURLOPT_URL, "https://ourwebsite/cgi-
bin/dispatch.cgi");
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 100);
        curl_setopt($ch, CURLOPT_VERBOSE, 1); // Be verbose

        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - Beginning of CURL\n";
        $fp = fopen("/var/log/ourwebsite/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        $response = curl_exec($ch);

        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - End of CURL\n";
        $fp = fopen("/var/log/ourwebsite/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        $succeeded = curl_errno($ch); // == 0 ? true : false;

        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - Just after succeeded\n";
        $fp = fopen("/var/log/ourwebsite/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        curl_close($ch);

        $now = time();
        $gmtoffset = $now - 14400;
        $dtime = $date = date("i:s",$gmtoffset);
        $entry_line = "$dtime - Return from CURL, end of function connect
($Service, $DC_NUM, $MoreData)\n";
        $fp = fopen("/var/log/ourwebsite/gt/trouble.log", "a");
        fwrite($fp, $entry_line);
        fclose($fp);

        return $response;
}

-- END CODE --

--
Brian Wilkins
brian_at_hcc.net
Heritage Communications Corporation
  Melbourne, FL     USA     32935
Received on 2004-09-26