curl或file_get_contents忽略输出

时间:2017-10-13 17:19:32

标签: php curl

我需要在服务器1的不同服务器上运行php代码(让它称之为服务器2)。

在服务器1中,我有类似的东西

select * from table_2  
join table2 on table1
where table_2.column = table.column

问题是,这个请求可能需要很长时间,而且我不需要获得输出。我只是想触发脚本而不必等待或获得输出。

无论如何要完成我想要的东西吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

您可以使用套接字。请参阅此example

编辑:

以下是上述链接中的代码:

// Example:
// post_async("http://www.server.com/somewhere",array("foo" => 123, "bar" => "ABC"));

function post_async($url, $params)
{
    // Build POST string
    foreach ($params as $key => &$val) {
      if (is_array($val)) $val = implode(',', $val);
      $post_params[] = $key.'='.urlencode($val);
    }
    $post_string = implode('&', $post_params);

    // Connect to server
    $parts=parse_url($url);
    $fp = fsockopen($parts['host'],isset($parts['port'])?$parts['port']:80,$errno, $errstr, 30);

    // Build HTTP query             
    $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";
    $out.= $post_string;

    // Send data and close the connection
    fwrite($fp, $out);
    fclose($fp);
}
相关问题