Forum Moderators: coopster

Message Too Old, No Replies

Sending multiple submissions during one curl connection

         

ocon

1:47 am on Aug 3, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



I am using a script to submit new posts to my WordPress installation using curl.

I have to run the curl function ten times when I run the script, once per each new post in the batch. This seems terribly wasteful and slow, having to connect, send, and disconnect, only to do it nine times immediately thereafter.

Is there a way to optimize this process so I can do it all it one connection/execution?

$XML = "<title>Title</title><category>Category</category>Body";
$request = xmlrpc_encode_request('blogger.newPost',array('','',"username","password",$XML,1));

$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, "http://www.mysite.com/xmlrpc.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_exec($ch);
curl_close($ch);

brotherhood of LAN

6:30 am on Aug 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It depends on the script you're posting to. It'd be most convenient if you could just put your blog posts into an array and fire them all over in the one request, but the receiving script may only be designed to take one post at a time.

Anyways, curl_multi_init [php.net] might be what you're after.

d3vrandom

2:07 pm on Aug 3, 2011 (gmt 0)

10+ Year Member



If your wordpress installation is on the same server as this above script then why not create a wordpress plugin to insert the data directly into the wordpress database? XML-RPC is for remote posting of content.

ocon

10:20 pm on Aug 5, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thank you very much.