简体   繁体   English

php cURL脚本运行两次

[英]php cURL script run twice

I have a tragedic issue, with my curl, i want to post one time and my action is executed twice. 我有一个悲剧性的问题,我的卷曲,我想发布一次,我的行动被执行两次。

I don't have two curl_exec() or is not a html output problem, and i have aldready search to my best friend Google, and to other post on stackoverflow. 我没有两个curl_exec()或者不是html输出问题,我已经搜索到了我最好的朋友Google,以及其他关于stackoverflow的帖子。 My request is send successfully, but the last problem is that ... 我的请求发送成功,但最后一个问题是......

My config 我的配置

      CURLOPT_URL            => $url,
      CURLOPT_RETURNTRANSFER => false,      
      CURLOPT_HEADER         => false,      
      CURLOPT_FAILONERROR    => true,      
      CURLOPT_POST           => true,       
      CURLOPT_POSTFIELDS     => $postFields, 
      CURLOPT_VERBOSE        => true,
      CURLOPT_SSL_VERIFYPEER => 0,
      CURLOPT_SSL_VERIFYHOST => 0,
      CURLOPT_PROTOCOLS      =>  CURLPROTO_HTTP,
      CURLOPT_USERAGENT      => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'

$CURL=curl_init();

if(empty($CURL)){die("ERREUR");}
       curl_setopt_array($CURL,$options);

      curl_exec($CURL);

        curl_close($CURL);  

      $content = ob_get_contents();
      ob_end_clean();

      if(curl_errno($CURL)){
            echo "ERREUR curl_exec : ".curl_error($CURL); 
      }

      ob_end_flush();


echo $content;

Have you any idea to resolve that, thanks. 你有什么想法解决这个问题,谢谢。

Your curl only executes once but outputs twice. 你的卷曲只执行一次,但输出两次。 The first one comes from curl_exec($CURL) , because CURLOPT_RETURNTRANSFER is false, 第一个来自curl_exec($CURL) ,因为CURLOPT_RETURNTRANSFER为false,

TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. TRUE将传输作为curl_exec()的返回值的字符串返回,而不是直接输出。 curl_setopt curl_setopt

The second one is obviously from echo $content; 第二个显然来自echo $content;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM