簡體   English   中英

(PHP)curl_request_async不起作用

[英](PHP) curl_request_async does not work

我從如何在PHP中發出異步GET請求中獲取了函數curl_request_async

 // $type must equal 'GET' or 'POST'
function curl_request_async($url, $params, $type='POST')
{
  foreach ($params as $key => &$val) {
    if (is_array($val)) $val = implode(',', $val);
    $post_params[] = $key.'='.urlencode($val);
  }
  $post_string = implode('&', $post_params);

  $parts=parse_url($url);

  $fp = fsockopen($parts['host'],
      isset($parts['port'])?$parts['port']:80,
      $errno, $errstr, 30);

  // Data goes in the path for a GET request
  if('GET' == $type) $parts['path'] .= '?'.$post_string;

  $out = "$type ".$parts['path']." HTTP/1.1\r\n";
  $out.= "Host: ".$parts['host']."\r\n";
  $out.= "Content-Type: application/x-www-form-urlencoded\r\n";
  $out.= "Content-Length: ".strlen($post_string)."\r\n";
  $out.= "Connection: Close\r\n\r\n";
  // Data goes in the request body for a POST request
  if ('POST' == $type && isset($post_string)) $out.= $post_string;

  fwrite($fp, $out);
  fclose($fp);
}

它可以與以前的主機完美配合,但是在我移至新主機后,它無法正常工作。 我已經安裝了php-curl,但這就像函數只是不調用url一樣。

也沒有錯誤。 請幫助我已經堅持了好幾天。

您可以驗證的一件事是,是否可以在服務器上調用fsockopen,發布的代碼不使用curl,而是嘗試直接打開套接字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM