Problems with curl :-S

apps

#1

I’m trying to install a script to show the last few songs I’ve listened to. I haven’t been able to use it sucessfully on my DH account because it uses file_get_contents and well I don’t know how to use curl instead of that.

The original code is:

$xml = @file_get_contents(DEBUG===true ? ‘aliguana.xml’
: ‘http://ws.audioscrobbler.com/1.0/user/’.$user.’/recenttracks.xml’);

I tried replacing that bit with the curl stuff but it just isn’t working.

Here’s what I have:

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, ‘http://ws.audioscrobbler.com/1.0/user/’.$user.’/recenttracks.xml’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$xml = curl_exec($ch);
curl_close($ch);
// display file
echo $xml;

Any help would be vastly appreciated. The original script and instructions can be found at http://www.audioscrobbler.net/wiki/RecentlyPlayedImageV2 and it’s the RPI.php file I’m trying to change.

The Insane Cabbit
My Blog http://www.sounanda.com
My web store:
http://www.marciesgifts.com
Send me a pm if you want cms or forum software installed (for a fee)


#2

[quote]The original code is:

$xml = @file_get_contents(DEBUG===true ? ‘aliguana.xml’
: ‘http://ws.audioscrobbler.com/1.0/user/’.$user.’/recenttracks.xml’);[/quote]
There is a tenary operator in that bit of code. If you write it out in a longwinded way, it would look like this:if(DEBUG===true) { $xml = file_get_contents('aliguana.xml'); } else { $xml = file_get_contents('http://ws.audioscrobbler.com/1.0/user/'.$user.'/recenttracks.xml'); }That means that the cURL version of your script will need to be a little more sophisticated. Try something like this:$url = (DEBUG===true) ? 'aliguana.xml' : 'http://ws.audioscrobbler.com/1.0/user/'.$user.'/recenttracks.xml'; $ch = curl_init(); $timeout = 5; // set to zero for no timeout curl_setopt ($ch, CURLOPT_URL, $url; curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $xml = curl_exec($ch); curl_close($ch);I have no direct experience of using such tools (or with cURL, for that matter), so you’ll have to try it out.


Simon Jessey
Keystone Websites | si-blog


#3

Hmm that doesn’t quite work. While it ddid get the information, instead of generating the image with it, it turned into garbage :frowning:

This is seriously driving me crazy. I’ve tried various things, neither of which is working. I removed the echo part since the original script doesn’t use it and I get the image but no information in it :’(

The Insane Cabbit
My Blog http://www.sounanda.com
My web store:
http://www.marciesgifts.com
Send me a pm if you want cms or forum software installed (for a fee)


#4

Since it is sending garbage could it be a problem with the header? I beleive there is a header option for curl.
Just a thought
Silk


#5

Well, I had the script to echo the information, which wasn’t needed. It’s supposed to show the information within a generated image file. I’ve given up on getting this script to work with DH. I have another account elsewhere that doesn’t disable file_get_contents so I will have to use it instead. This makes Ryo-ohki very unhappy XD but oh well.

The Insane Cabbit
My Blog http://www.sounanda.com
My web store:
http://www.marciesgifts.com
Send me a pm if you want cms or forum software installed (for a fee)


#6

You can always compile your own version of PHP that has it enabled.


Simon Jessey
Keystone Websites | si-blog


#7

I completely forgot about that lol XD I’m going to give it a shot

The Insane Cabbit
My Blog http://www.sounanda.com
My web store:
http://www.marciesgifts.com
Send me a pm if you want cms or forum software installed (for a fee)


#8

I can’t seem to compile php to save my life :frowning: I tried following the instructions on the wiki but that stuff just isn’t working. I go into ssh and type vim installscript (it seems that the file created is .installscript.swp?) and well some crap comes up but I continue on with the instructions and press i and paste the info. When I hit esc it does nothing and try to type :wq and more gobbledygook appears and I hit enter. Even if I close out the screen and go back in to make the file executable it says you can’t do that to a binary file. What am I doing wrong?

The Insane Cabbit
My Blog http://www.sounanda.com
My web store:
http://www.marciesgifts.com
Send me a pm if you want cms or forum software installed (for a fee)