不支持fsockopen但支持culr環(huán)境下下ucenter與modoer通訊問題
更新時(shí)間:2011年08月12日 16:20:30 作者:
網(wǎng)站上線,modoer與ucenter 下不能通訊折騰了我差不多二天,開始都以為自己的配置出問題,移植了平臺(tái)后就不能通訊了,修改了幾次配置,都沒有成功
所以就懷疑是否編碼問題,或者文件權(quán)限問題,或者是不是函數(shù)不支持問題,經(jīng)過排查發(fā)現(xiàn)原來是萬網(wǎng)的L1主機(jī)不支持fsockopen,在文件uc_client/client.php中的uc_fopen中出現(xiàn)了問題,這里的代碼是這樣:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$matches = parse_url($url);
!isset($matches['host']) && $matches['host'] = '';
!isset($matches['path']) && $matches['path'] = '';
!isset($matches['query']) && $matches['query'] = '';
!isset($matches['port']) && $matches['port'] = '';
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
if(!$fp) {
return '';//note $errstr : $errno \r\n
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
fsockopen函數(shù)不能使用,因些就只能靠其它方法了,幸虧支持curl,file_get_contents也支持,經(jīng)考慮就用curl吧,修改了uc_fopen函數(shù),如下;
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
if (curl_errno($curl)) {
echo '<pre><b>錯(cuò)誤:</b><br />'.curl_error($curl);
}
curl_close($curl);
return $return;
}
于是modoer下的uc_client/client.php和uchome下的uc_cilent/client.php,就這樣修改了uc_open函數(shù),呵呵,第一次使用curl,網(wǎng)上的資料還是好多的,所以也沒有什么阻礙,不過就不知這個(gè)修改會(huì)不會(huì)影響其它的東西,還有待測(cè)試羅。。。。
復(fù)制代碼 代碼如下:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$matches = parse_url($url);
!isset($matches['host']) && $matches['host'] = '';
!isset($matches['path']) && $matches['path'] = '';
!isset($matches['query']) && $matches['query'] = '';
!isset($matches['port']) && $matches['port'] = '';
$host = $matches['host'];
$path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
//$out .= "Referer: $boardurl\r\n";
$out .= "Accept-Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
if(!$fp) {
return '';//note $errstr : $errno \r\n
} else {
stream_set_blocking($fp, $block);
stream_set_timeout($fp, $timeout);
@fwrite($fp, $out);
$status = stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose($fp);
return $return;
}
}
fsockopen函數(shù)不能使用,因些就只能靠其它方法了,幸虧支持curl,file_get_contents也支持,經(jīng)考慮就用curl吧,修改了uc_fopen函數(shù),如下;
復(fù)制代碼 代碼如下:
function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
$return = '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
if (curl_errno($curl)) {
echo '<pre><b>錯(cuò)誤:</b><br />'.curl_error($curl);
}
curl_close($curl);
return $return;
}
于是modoer下的uc_client/client.php和uchome下的uc_cilent/client.php,就這樣修改了uc_open函數(shù),呵呵,第一次使用curl,網(wǎng)上的資料還是好多的,所以也沒有什么阻礙,不過就不知這個(gè)修改會(huì)不會(huì)影響其它的東西,還有待測(cè)試羅。。。。
您可能感興趣的文章:
- destoon整合ucenter后注冊(cè)頁面不跳轉(zhuǎn)的解決方法
- destoon整合UCenter圖文教程
- codeigniter集成ucenter1.6雙向通信的解決辦法
- 單點(diǎn)登錄 Ucenter示例分析
- 關(guān)于shopex同步ucenter的redirect問題,導(dǎo)致script不運(yùn)行
- UCenter 批量添加用戶的php代碼
- UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexists
- UCenter中的一個(gè)可逆加密函數(shù)authcode函數(shù)代碼
- php將會(huì)員數(shù)據(jù)導(dǎo)入到ucenter的代碼
- UCenter Home二次開發(fā)指南
- 簡(jiǎn)單分析ucenter 會(huì)員同步登錄通信原理
相關(guān)文章
php中把對(duì)象轉(zhuǎn)換為數(shù)組幾種簡(jiǎn)單巧妙的方法
在PHP中,對(duì)象是一種復(fù)雜的數(shù)據(jù)類型,它可以包含多個(gè)屬性和方法,有時(shí)候我們需要將對(duì)象轉(zhuǎn)換為數(shù)組進(jìn)行操作,比如將對(duì)象存儲(chǔ)到數(shù)據(jù)庫中,或者將對(duì)象轉(zhuǎn)換為JSON格式等情況,對(duì)象轉(zhuǎn)數(shù)組不能用遞歸實(shí)現(xiàn)轉(zhuǎn)換,本文幾種簡(jiǎn)單巧妙的方法2023-09-09phpinfo()中Loaded Configuration File(none)的解決方法
這篇文章主要給大家介紹了phpinfo()中Loaded Configuration File(none)問題的解決方法,需要的朋友可以參考借鑒,下面來一起看看吧。2017-01-01PHP使用flock實(shí)現(xiàn)文件加鎖的方法
這篇文章主要介紹了PHP使用flock實(shí)現(xiàn)文件加鎖的方法,實(shí)例分析了flock文件鎖的使用技巧,需要的朋友可以參考下2015-07-07php實(shí)現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)專業(yè)獲取網(wǎng)站SEO信息類,實(shí)例分析了seoreport類針對(duì)網(wǎng)站SEO信息檢查與獲取的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04PHPExcel實(shí)現(xiàn)表格導(dǎo)出功能示例【帶有多個(gè)工作sheet】
這篇文章主要介紹了PHPExcel實(shí)現(xiàn)表格導(dǎo)出功能,結(jié)合實(shí)例形式分析了PHPExcel針對(duì)帶有多個(gè)工作sheet的表格導(dǎo)出相關(guān)操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-06-06PHP7基于curl實(shí)現(xiàn)的上傳圖片功能
這篇文章主要介紹了PHP7基于curl實(shí)現(xiàn)的上傳圖片功能,結(jié)合實(shí)例形式對(duì)比分析了php5.5之前與php7版本的curl圖片上傳功能相關(guān)實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2018-05-05php實(shí)現(xiàn)的雙向隊(duì)列類實(shí)例
這篇文章主要介紹了php實(shí)現(xiàn)的雙向隊(duì)列類,是數(shù)據(jù)結(jié)構(gòu)中非常重要的一個(gè)數(shù)據(jù)結(jié)構(gòu)類型,需要的朋友可以參考下2014-09-09