curl-and-php
RE: Problem with curl_exec and server setup
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:
http://sg.php.net/manual/en/function.curl-error.php
With regards,
Liu Shan Shui
me_at_lx.sg
"Life would be much easier if I had the source code." - Anonymous
From: curl-and-php-bounces_at_cool.haxx.se
[mailto:curl-and-php-bounces_at_cool.haxx.se] On Behalf Of Yazmin Media
Sent: Wednesday, May 13, 2009 11:55 PM
To: curl-and-php_at_cool.haxx.se
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);
var_dump($Headers);
I also get:
array(19) {
["url"]=>
string(59) "http://twitter.com/statuses/update.xml?status=testing+1+2+3"
["http_code"]=>
int(0)
["header_size"]=>
int(0)
["request_size"]=>
int(218)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.122609)
["namelookup_time"]=>
float(1.8E-5)
["connect_time"]=>
float(0.122528)
["pretransfer_time"]=>
float(0.122531)
["size_upload"]=>
float(0)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(0)
["upload_content_length"]=>
float(-1)
["starttransfer_time"]=>
float(0.122605)
["redirect_time"]=>
float(0)
Since a successful update should only return int(200) for http_code, I then
added:
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
here:
http://twitter.slawcup.com/twitter.class.phps
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?
Thanks!
Yazmin
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2009-05-14