PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 14, 2022

[FIXED] how to make non blocking call in php

 September 14, 2022     curl, exec, php     No comments   

Issue

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



Answered By - user562854
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing