PDA

View Full Version : HELP: plugin using curl



manish
06-15-2006, 12:46 AM
I'm trying to write my first plugin for vbulletin, but i cant seem to get it to work. I'm trying to implement an API from a 3rd party site to add more information about a particular user in their member profile. The API is easy to implement and can be done using php and curl.

However, i cant seem to get vbulletin to execute the curl commands to retrieve the data. It seems to timeout for some reason. The 3rd party site has a php wrapper to make it easier to implement the API. I used this wrapper from the command line and i'm able to retrieve the data just fine. When i use it in vbulletin, it does NOT execute the curl commands.

Also, i'm running the vbulletin on my local machine to test it out. I ran ethereal along side vbulletin and i do not see any outgoing packets for making the call to the 3rd party site. This is why i think vbulletin is not executing the curl.

Am i doing something wrong? This is my first time using vbulletin. Is there some switch or setting i forgot to set?

Please help, thanks in advance.

Noppid
06-15-2006, 01:08 AM
You need to post the code so we can read it.

Note: I think local host testing is a waste of time. Often the app breaks in the real world or don't work as expected to begin with.

manish
06-15-2006, 04:00 PM
i dont think its really necessary to post all the code. I've debugged and found the portion that is not working. It the call to this function:




function send_request($request, $url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-POST_DATA_FORMAT: xml'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}



It times out, but it does not send any data.

Noppid
06-15-2006, 10:05 PM
Postfileds are like submitting a form, not a url. If the request is supposed to have the variables in the URL, URL encode the URL with the vars and skip the post data. If you are submitting to a form and if $request is correct, carry on.

You are specifically telling the reciever that you are sending xml it looks like to me. Is the reality that you are expecting xml back? If so, use the deafault http 1.0 header in curl by doing nothing.

Then $data should contain the xml array for processing if that is what you expect.

Use CURLOPT_TIMEOUT to stop the server time out. Set it to like 5 seconds max so you can work quicker. I have most of mine at 1 or 2 seconds.