I found some PHP code on the ‘net that supposedly will help me send some text from my web site to be posted in a twitter feed.
However, it just dies on the curl_init() part. The browser shows an empty page (no HTML content whatsoever), and the code stops executing.
Here is the code:
$url = 'http://twitter.com/statuses/update.xml';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$body");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
I am testing on Ubuntu 11.04, using NetBeans (yes, I know Netbeans is designed for Java debugging, but it’s free and has a very good PHP debugging plugin) with xdebug. I’m testing on a local Apache 2.2 server.
I’ve tried running the debugger to see where it fails, and the debugger also bails when the code hits the curl_init() part. It simply exits the debugger, and the browser, as mentioned above, shows only an empty page.
Is there something I need to configure or do to get curl_init() to actually do stuff?
Most probably the
curlmodule is not installed or enabled in your PHP setup. You can check for this in various ways:extension_loaded('curl')(as mentioned in that page, you can do the same from the command line with thephp -mcommand but be careful — I have see installations where command line PHP was using a different php.ini that the Apache module!)function_exists('curl_init')phpinfo()If
curlis not installed (as it sounds like), install it and your problem is solved.