Search code examples
phpcurlexec

how to make non blocking call in php


I am using a php script to upload lot of files. I am using the CURL command . The remote server accepts only POST requests. But when I execute the below script it processes the first request and waits until the first file is uploaded. Is there a way to make it non blocking and run simultaneous 2 curl upload requests .Find the code sample below.

<?php
  $arr= array(somefile1.txt,somefile2.txt);
  for ( $i=0;$i<2;$i++) {
     $cmd = "curl  -F name=aaa -F type=yyy  FileName=@/xxxxx/xxxx/$arr[$i] http://someurl.com";
     print "Executing file ";
     shell_exec("nohup  $cmd  2> /dev/null & echo $!" );
     print "=======  done ================";
  }
?>

Solution

  • There is a good article about "multithreading", take a look at it here: Multithreading in PHP with CURL