本文介绍了通过已经打开的套接字卷曲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道有没有办法使用 curl
trhough已经打开的套接字,类似,适应这:
I wonder if there's a way to use curl
trhough an already open socket, something like, adapting this:
<?php
$fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
使用 curl_exec()
code> fgets($ fp,128)
to use curl_exec()
instead of fgets($fp, 128)
(或任何其他方式使用 curl )
,所有的时间,我的目标是阅读twitter流api)
(or, any other way to use curl()
over the same stream all the time, my goal is to read the twitter stream api)
谢谢
推荐答案
这可能适用于你,因为你正在处理Twitter Stream API
This might work for you since you are dealing with Twitter Stream API
set_time_limit(0);
$ch = curl_init();
echo "<pre>";
curl_setopt($ch, CURLOPT_URL, "https://sitestream.twitter.com/2b/site.json");
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'cgets');
curl_setopt($ch, CURLOPT_BUFFERSIZE, 128);
curl_setopt($ch, CURLOPT_USERPWD, 'user:password');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000000);
curl_exec($ch);
function cgets($ch, $string) {
$length = strlen($string);
printf("Received %d byte\n", $length);
flush();
return $length;
}
这篇关于通过已经打开的套接字卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!