PHP slowness with POST request

Discussion in 'PHP' started by FKereki, Apr 19, 2007.

  1. #1
    'm trying to access a web service that requires a POST operation, and I've managed to so in at least three different ways, but it's always SLOW!!

    My first try used fsockopen() and associated functions, and took about 30 seconds to get an answer. Then I tried the socket_xxxxx() functions, but the results were similar. Finally I used the curl_xxxxx() functions, and yet the same result.

    HOWEVER, I also did a similar try with Python, and I got the answer within 2 seconds!

    All the PHP programs worked fine, and so did the Python one, but I couldn't get any speed out of PHP.

    Are there any known restrictions/problems with this? Any solutions?

    Thanks!
     
    FKereki, Apr 19, 2007 IP
  2. linkstraffic

    linkstraffic Well-Known Member

    Messages:
    388
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    133
    #2
    have you tried using the CURL library?
     
    linkstraffic, Apr 20, 2007 IP
  3. FKereki

    FKereki Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is the curl way I tried:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $urlToOpen.$pathToOpen);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept-Encoding: identity"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Connection: close"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: binary/octet-stream"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Length: ".strlen($dataToSend)));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataToSend);
    $answer = curl_exec($ch);
    curl_close($ch);

    And it was every bit as slow as the fsockopen() or socket_xxx() versions!
     
    FKereki, Apr 20, 2007 IP