我从数据库表中提取了一组近1500个数据,对于每个数据,我应该通过CURL以这种方式调用端点:
for($i=0; $i <1500; $i++) {
$headers = [
'Host: www.hostname.it',
'Accept: application/json, text/javascript, */*; q=0.01',
'X-Requested-With: XMLHttpRequest',
'Accept-Language: it-it',
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
'Origin: https://www.desiderimagazine.it',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.1 Safari/603.1.30',
'Connection: close',
'Referer: https://www.hpstname.it/page/registrazione?utm_source=gate2000&utm_medium=display&utm_campaign=ghh_gen18_regist&utm_content=leadcampaign2',
'Content-Length: '.mb_strlen($post_fields, '8bit')
];
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_ENCODING , "");
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 24000);
curl_setopt($ch, CURLOPT_CONNECTIONTIMEOUT, 24000);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_fields); //Post Fields
$result = curl_exec($ch);
// .. here I save the result on database
}
我运行脚本在浏览器上插入其url并且它可以正常工作(我正确地看到数据库和端点响应的结果),前20-30个数据,或多或少。之后我在sistematically得到一个
504错误 - 网关错误超时
我怀疑它可能是我执行它的方式,但必须有一些配置我可以更改我的代码以修复它。
由于