我已经在我的服务器上设置了ScRapyd,一切似乎都运行得很好.我可以使用cURL来获取我的蜘蛛列表,比如curl -u super:secret http://111.111.111.111:6800/listspiders.json?project=myproject
.我也可以用curl -u super:secret http://111.111.111.111:6800/schedule.json -d project=myproject -d spider=spider1
来启动蜘蛛.
现在,我想在PHP中执行此操作.第一个cURL命令运行正常:
<?php
$username='super';
$password='secret';
$ch = curl_init();
$url = 'http://111.111.111.111:6800/listspiders.json?project=myproject';
#$url = "http://111.111.111.111:6800/schedule.json -d project=myproject -d spider=spider1";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$response = curl_exec($ch);
echo 'Type ($response): '.gettype($response). "<br/>";
echo 'Response: '.$response;
curl_close($ch);
?>
这将返回预期的响应:{"node_name": "ubuntu-s-1vcpu-512mb-10gb-fra1-01", "status": "ok", "spiders": ["spider1", "spider2"]}
.
然而,当我将上面代码片段中的URL更改为$url = "http://111.111.111.111:6800/schedule.json -d project=myproject -d spider=spider1";
时,我没有得到any响应.没有错误,什么都没有.gettype($response)
的回报是boolean
,不管它值多少钱.
同样,在使用终端时,curl命令运行正常,并返回类似{"node_name": "ubuntu-s-1vcpu-512mb-10gb-fra1-01", "status": "ok", "jobid": "6a885343fa8233a738bb9efa11ec2e94"}
的结果
任何关于这里正在发生的事情的提示,或者更好的解决问题的方法,都是非常感激的.