我有node.js服务器端:
var http = require('http');
var server = http.createServer(function (req, res) {
console.log(req.url);
}).listen(10001);
var io = require('socket.io').listen(server);
我尝试从PHP连接到此服务器,使用curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://'.$address);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_PORT, $port);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,true));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
为什么当我只有1时,我得到2个服务器请求(控制台显示网址“/”)? 我尝试使用socket.io进行聊天,并且需要从PHP执行一些操作。