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


RE: Problem with curl_exec and server setup

From: Liu Shan Shui <>
Date: Fri, 15 May 2009 01:28:41 +0800

Hi Yazmin,


So, are you saying that the code works fine, but just that it's returning 0
for the HTTP status code on your local server? Two suggestions here:

1. Run the app on a third server. If it's ok on there as well, chances are
the problem lies within the configuration of your local server.

2. Call curl_error($ch) within the script to see what's wrong with it.


More info:


With regards,

Liu Shan Shui

"Life would be much easier if I had the source code." - Anonymous


[] On Behalf Of Yazmin Media
Sent: Wednesday, May 13, 2009 11:55 PM
Subject: Problem with curl_exec and server setup


I'm working with the Twitter api and running into a weird issue with curl.
At first, I thought it was the code, however, after working with it with the
Twitter Dev Talk Google group, I decided to try the code out on another
server and found that it worked just fine.

So I need help troubleshooting, I'm just not sure where to start.

This is what is going on...using PHP, I know that I can successfully get a
feed of a user's latest statuses using this code:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$this->Username:$this->Password");
    $xml = curl_exec($ch);

    $data = simplexml_load_string($xml);

However, when I send an update, the same code, with the addition of a line
for CURLOPT_POST, returns bool(false):

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$this->Username:$this->Password");

    curl_setopt($ch, CURLOPT_POST, 1);
    $xml = curl_exec($ch);

    $data = simplexml_load_string($xml);

(I tested that by adding a var_dump($data) after the last line.)

If I add:

    $Headers = curl_getinfo($ch);

I also get:

array(19) {
  string(59) ""
Since a successful update should only return int(200) for http_code, I then

    var_dump(curl_getinfo($ch, CURLINFO_HTTP_CODE));
which returned int(0). I also checked the Twitter account and saw that the
new status was indeed posted.

At that point, I was told that it looks like I'm possibly getting return
values on a curl request other than the one posting the status update to
Twitter. Like I said, I do know that the status update is successful as it
shows up on the account, however, on this server, I'm not getting the return
values I should from the curl_exec() function.

The class I'm working with was written by David Billingham and can be found

I am running the following:

- OSX 10.5.6
- MAMP 1.7.2
- PHP 5
- libcurl 7.18.2

Since the code works as is on another server, I thought it might have
something to do with how curl is setup in MAMP or MAMP itself...tackling
curl first. Suggestions?


Received on 2009-05-14