curl 异步执行操作

来源:互联网 发布:创建表的sql语句主键 编辑:程序博客网 时间:2024/04/28 18:34

上面的是post请求下面的是get请求
$remeote_sever 是表示目标路径, 要异步操作就要对其进行一下超时处理。 最小就是一秒。所以调用一次就最长会有一秒的延迟。

function request_by_curl($remote_server){    $post_string = "name=荷花";    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $remote_server);    curl_setopt($ch, CURLOPT_POST, true);    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);    curl_setopt($ch, CURLOPT_TIMEOUT, 1);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    $response = curl_exec($ch);    curl_close($ch);    return $response;}function re($url){    $post_string = "name=荷花";    $url = $url . '?' . $post_string;    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_TIMEOUT, 1);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    curl_exec($ch);    curl_close($ch);}
0 0