我对套接字有简单的 CURL 请求,它返回进程 pid。问题是有一些额外的字符/符号是看不见的。我的代码是:
for ($i = 0; $i < 3; $i++ ) {
$ch = curl_init($server);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '<ping></ping>');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
$output = array(
'result' => curl_exec($ch),
'info' => curl_getinfo($ch),
'error' => curl_error($ch)
);
curl_close($ch);
var_dump($output['result']);
var_dump(trim($output['result']));
var_dump($pid);
echo "----------------\n";
if (trim($output['result']) == $pid)
die('TRUE');
sleep(2);
}
die('FALSE');
输出如下所示:
bool(false)
string(0) ""
string(5)
"14262"
----------------
string(7) "14262"
string(7) "14262"
string(5 ) "14262"
----------------
字符串(7) "14262"
字符串(7) "14262"
字符串(5) "14262"
--------- --------
错误