0

I was wondering if it was possible to concurrently execute two post_to_url functions randomly at the same time -- the post_to_url function is a cURL request and $data are variables from a form. I have tried to rewrite the post_to_url function with curl_multi handle but it did not work. thanks for the help - much appreciated.

$urls = array(
   "http://examplesite1.com/cgi-bin/maxuseradmin.cgi",
   "http://examplesite2?fid=6646588e54",
   "http://examplesite1?fid=2fb44e3888"
);

$data = array(
    $data2,
    $data3,
    $data4
);
$x = rand(0,2);
post_to_url($urls[x], $data[x]);
post_to_url($urls[x], $data[x]);
DEM
  • 333
  • 2
  • 4
  • 16
  • You can always try to go for multithreading: http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications – Mihai Todor Aug 04 '12 at 14:37
  • Or you might want to check out [async sockets](http://stackoverflow.com/questions/1432477/can-php-asynchronously-use-sockets). It will probably be simpler in this case, especially if you manage to find a decent HTTP library that uses async sockets. – Vatev Aug 04 '12 at 14:46
  • Hi Vatev, im sort of new to more advanced php type of things. is there a little example that can help me get on my way? thanks – DEM Aug 04 '12 at 15:01

1 Answers1

1

Try this Class

http://peecfw.googlecode.com/svn/trunk/Application/com/loadable/curl/CURL_thread.php

You can call it like this

$cURL = new CURL();
$cURL->addSession("https://www.example.com/?data=test");
$cURL->addSession("https://www.example2.com/?data=test");
$responses = $cURL->exec();  //This array will contain all responses
$cURL->clear();
Hanky Panky
  • 46,730
  • 8
  • 72
  • 95