Hello Deconstructing with the help of curls in the url array array:

function curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, " Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 400); $output = curl_exec($ch); if(output === false) { echo 'Ошибка curl: ' . curl_error($ch) . 'Код curl: ' . curl_errno($ch); } curl_close($ch); return $output; } foreach ($urls as url){ $result = curl($url); } 

But in some cases, when the result is displayed, everything goes well, but most of them return Ошибка curl: malformed Код curl: 3 , although the links are working and displayed correctly in the browser. Put sleep() to slow down the execution of the script - it does not help. What could be the problem? Thank.

  • Something I see inside the loop is the definition of the function, not its call. For what purpose do you give us the code in this way, which in principle cannot work? and why you have 2 times curl_exec occurs? - teran
  • Added just to demonstrate, and so it is clear how it works. But if not, I can redo it, if that's the whole problem for you - Roma Tulaydan
  • Now add an example URL on which swears. Moreover, if the request is a redirect, then write the whole chain URL. - teran
  • Doesn't it work for you from a separate URL? because works for me. PS: output instead of $output in if e place is written - teran

0