curl php post - 服务不可用 - 达到最大活动客户端数
curl php post - Service Unavailable - Maximum number of active clients reached
你好我正在做curl
PHPPOST请求(因为跨域来源),我遇到了一个问题。 Post 请求被发送到一台托管我无法控制的自定义 Web 服务器的机器。第一个请求(比如 15-20 是可以的)但是在这个请求数量之后我得到 503 error
响应错误消息
Service Unavailable - Maximum number of active clients reached.
我想每次发送请求时 curl 都会创建一个新连接。我还假设机器服务器只能打开几个连接。
这是我的 php 代码:
$data = array("getTags" => array("Start_dav","CutON"), "includeTagMetadata" => false);
$data_string = json_encode($data);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,"http://domainipaddres/");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, "SID=8c81775da6");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Connection: Keep-alive',
'Keep-alive: 300'
)
);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
我真的需要弄明白,但是在尝试了 2 天不同的选项和 header 数据后,我无法让它工作。如何强制 curl 只使用一个连接?
非常感谢
编辑:我今天发现了一个问题。服务器只能有 3 个活动客户端。我发现服务器的第一个响应 header 是 SET cookie,我需要在另一个请求中使用该 cookie。我手动设置它并且它有效。有什么方法可以自动执行此操作吗?
我今天解决了这个问题。我检查了响应 header 并看到服务器设置了 cookie。我只需要保存 cookie 并将其用于其他请求及其工作。这是部分代码:
$data_string = json_encode($data);
$agent= 'Mozilla/5.0 (Windows; U;Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9';
//open connection
$ch = curl_init();
$f = fopen('request.txt', 'w'); //writes headers to this file
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,"domainipaddress");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
$tmpfname = dirname(__FILE__).'/cookie.txt'; //saves the cookie from server
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
curl_setopt( $ch, CURLOPT_STDERR, $f );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Connection: keep-alive',
"Keep-Alive: 300"
)
);
//execute post
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
fclose($f);
还是谢谢你
你好我正在做curl
PHPPOST请求(因为跨域来源),我遇到了一个问题。 Post 请求被发送到一台托管我无法控制的自定义 Web 服务器的机器。第一个请求(比如 15-20 是可以的)但是在这个请求数量之后我得到 503 error
响应错误消息
Service Unavailable - Maximum number of active clients reached.
我想每次发送请求时 curl 都会创建一个新连接。我还假设机器服务器只能打开几个连接。
这是我的 php 代码:
$data = array("getTags" => array("Start_dav","CutON"), "includeTagMetadata" => false);
$data_string = json_encode($data);
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,"http://domainipaddres/");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, "SID=8c81775da6");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Connection: Keep-alive',
'Keep-alive: 300'
)
);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
我真的需要弄明白,但是在尝试了 2 天不同的选项和 header 数据后,我无法让它工作。如何强制 curl 只使用一个连接?
非常感谢
编辑:我今天发现了一个问题。服务器只能有 3 个活动客户端。我发现服务器的第一个响应 header 是 SET cookie,我需要在另一个请求中使用该 cookie。我手动设置它并且它有效。有什么方法可以自动执行此操作吗?
我今天解决了这个问题。我检查了响应 header 并看到服务器设置了 cookie。我只需要保存 cookie 并将其用于其他请求及其工作。这是部分代码:
$data_string = json_encode($data);
$agent= 'Mozilla/5.0 (Windows; U;Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9';
//open connection
$ch = curl_init();
$f = fopen('request.txt', 'w'); //writes headers to this file
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,"domainipaddress");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
$tmpfname = dirname(__FILE__).'/cookie.txt'; //saves the cookie from server
curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_VERBOSE, 1 );
curl_setopt( $ch, CURLOPT_STDERR, $f );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_FORBID_REUSE, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'Connection: keep-alive',
"Keep-Alive: 300"
)
);
//execute post
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
fclose($f);
还是谢谢你