導航:首頁 > 編程語言 > getphpversion

getphpversion

發布時間:2022-07-03 15:51:44

php Curl出現403錯誤怎麼辦

使用curl抓網頁下來處理,為了穿牆方便,使用Privoxy作為代理,便於選擇哪些網站使用proxy、哪些不用。但今天卻遇到了奇怪的問題,訪問google這些網站居然都返回403錯誤,而訪問其他的一些網站沒事,如果設置為不使用proxy則都能正常訪問。
難道google就不讓用proxy連接么?顯然不可能,所以打開curl的信息輸出(curl_setopt($this->mSh,CURLOPT_VERBOSE,1);)看看,得到以下結果:
.代碼如下:
*Trying127.0.0.1...*connected
*Connectedto127.0.0.1(127.0.0.1)port8118(#0)
*EstablishHTTPproxytunneltowww..com:80
>CONNECTwww..com:80HTTP/1.0
Host:www..com:80
User-Agent:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1)
Proxy-Connection:Keep-Alive
<HTTP/1.0403Connectionnotallowable
<X-Hint:,thenyouknowwhythishappens,-)
<
*TherequestedURLreturnederror:403
*
*Closingconnection#0
...Failed.
可以看到proxy伺服器工作正常,的確是返回了403錯誤,但原因肯定還在我這邊。終於,從網上(1of2,2of2)得到了點啟發──我使用的是proxytunnel而非proxy。
在代碼中,有這么一句:
.代碼如下:
curl_setopt($this->mSh,CURLOPT_HTTPPROXYTUNNEL,true);
curl_setopt($this->mSh,CURLOPT_PROXY,$phost);
php文檔中沒有詳細說明,不過mancurl中有詳細解釋,兩者都是代理,proxytunnel(-p參數)允許其他協議通過http代理傳輸,而proxy(-x參數)則只能走http協議。所以我猜測,google的伺服器和curl的proxytunnel不和,所以返回403。
禁用掉上面2行代碼的第一句後,curl訪問恢復正常。
比較奇怪的是,幾種操作系統下還不一樣,一台MACOSX就要顯式的禁用proxytunnel才可以,curl版本:
.代碼如下:
$curl--version
curl7.16.3(powerpc-apple-darwin9.0)libcurl/7.16.3OpenSSL/0.9.7lzlib/1.2.3
Protocols:
Features:GSS-
而另外一台ubuntu則完全不受影響,怎麼都能用,curl版本:
.代碼如下:
$curl--version
curl7.18.2(i486-pc-linux-gnu)libcurl/7.18.2OpenSSL/0.9.8gzlib/1.2.3.3libidn/1.10
Protocols:
Features:GSS-
MT主機上的centos也沒事,curl版本:
.代碼如下:
$curl--version
curl7.15.5(i686-redhat-linux-gnu)libcurl/7.15.5OpenSSL/0.9.8bzlib/1.2.3libidn/0.6.5
Protocols:
Features:GSS-
看來不完全是curl版本問題,MACOSX的確與眾不同啊。
還有一個原因也會導致curl返回403錯誤,如果設置了:
.代碼如下:
curl_setopt($ch,CURLOPT_NOBODY,true);
則需要緊跟著設置:
.代碼如下:
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,'GET');
不然會因為http伺服器不允許HEAD命令而返回403錯誤。參考:TroublewithacURLrequestinPHP(forums.devshed.com/php-development-5/trouble-with-a-curl-request-in-php-445222.html)。MACOSX上curl之所以特殊,也不排除是這種原因

② 這個PHP文件是什麼,是木馬嗎

我粗略的看了一下,感覺這是一個通過瀏覽器執行SQL的程序,有一定危險性。
最好刪了,或者把後綴 .php改成 .php_del 防止執行

③ php version 什麼意思

PHP,一個嵌套的縮寫名稱,是英文超級文本預處理語言(PHP:Hypertext Preprocessor)的縮寫。PHP 是一種 HTML 內嵌式的語言,是一種在伺服器端執行的嵌入HTML文檔的腳本語言,語言的風格有類似於C語言,現在被很多的網站編程人員廣泛的運用。PHP 獨特的語法混合了 C、java、Perl 以及 PHP 自創新的語法。它可以比 CGI 或者 Perl 更快速的執行動態網頁。用PHP做出的動態頁面與其他的編程語言相比,PHP是將程序嵌入到HTML文檔中去執行,執行效率比完全生成HTML標記的CGI要高許多;與同樣是嵌入HTML文檔的腳本語言JavaScript相比,PHP在伺服器端執行,充分利用了伺服器的性能;PHP執行引擎還會將用戶經常訪問的PHP程序駐留在內存中,其他用戶再一次訪問這個程序時就不需要重新編譯程序了,只要直接執行內存中的代碼就可以了,這也是PHP高效率的體現之一。PHP具有非常強大的功能,所有的CGI或者JavaScript的功能PHP都能實現,而且支持幾乎所有流行的資料庫以及操作系統。
PHP 最初是1994年Rasmus Lerdorf創建的,剛剛開始只是一個簡單的用Perl語言編寫的程序,用來統計他自己網站的訪問者。後來又用C語言重新編寫,包括可以訪問資料庫。在1995年以Personal Home Page Tools (PHP Tools) 開始對外發表第一個版本,Lerdorf寫了一些介紹此程序的文檔,並且發布了PHP1.0。在這早期的版本中,提供了訪客留言本、訪客計數器等簡單的功能。以後越來越多的網站使用了PHP,並且強烈要求增加一些特性,比如循環語句和數組變數等等,在新的成員加入開發行列之後,在1995年中,PHP2.0發布了。第二版定名為PHP/FI(Form Interpreter)。PHP/FI加入了對mySQL的支持,從此建立了PHP在動態網頁開發上的地位。到了1996年底,有15000個網站使用 PHP/FI;時間到了1997年中,使用PHP/FI的網站數字超過五萬個。而在1997年中,開始了第三版的開發計劃,開發小組加入了 Zeev Suraski 及 Andi Gutmans,而第三版就定名為PHP3。2000年,PHP4.0又問世了,其中增加了許多新的特性。

④ 這網頁中的音樂如何下載

第一步:
地址欄輸入javascript:document.write(document.body.outerHTML),按enter,察看源文件
第二步:
仔細看會找到PARAM NAME="URL" VALUE="http://www.music8.cc/include/geturl.php?id=2714"
把http://www.music8.cc/include/geturl.php?id=2714打開
會得到以下代碼

<ASX version = "3.0">
<entry skipifref="no">
<title>天下無雙-5080飛雪</title>
<author>5080飛雪</author>
<right>音樂吧 - www.music8.cc</right>
<ref href="/音頻廣告.mp3"/>
</entry>
<entry skipifref="no">
<title>天下無雙-5080飛雪</title>
<author>5080飛雪</author>
<right>音樂吧 - www.music8.cc</right>
<ref href="http://wma.music8.cc/upload/url/20101002021501356-74.mp3" />
</entry>
</asx>
其中http://wma.music8.cc/upload/url/20101002021501356-74.mp3就是地址
明白了嗎?

⑤ 用PHP study建織夢網站弄到根目錄後通過127.0.0.1出現<php /** * @version 進不去頁面

重新搭建環境吧,都沒搭建好沒有被編譯,重新弄一次,還搞不好的話再找額指導教學,省事省心,謝謝

⑥ php代碼 訪問者IP是中國的就跳轉到中文頁面,不是中國的就跳轉到英文頁面

可能原來伺服器有讀取ip所在地的介面吧,可能你那個判斷不好用了

放到index.php中
<?php
include_once 'class_iplocation.php';
$ip='222.132.78.170';
$iplo= new IpLocation();

$a_provinces=Array (
'0' => '河北',
'1' =>'海南',
'2' => '貴州',
'3' => '廣西',
'4' => '廣東',
'5' => '甘肅',
'6' => '福建',
'7' => '北京',
'8' => '安徽',
'9' => '河南',
'10' => '黑龍江',
'11' => '湖北',
'12' => '湖南',
'13' => '吉林',
'14' => '江蘇',
'15' => '江西',
'16' => '遼寧',
'17' => '內蒙古',
'18' => '寧夏',
'19' => '青海',
'20' => '山東',
'21' => '山西',
'22' => '陝西',
'23' => '上海',
'24' => '四川',
'25' => '天津',
'26' => '西藏',
'27' => '新疆',
'28' => '雲南',
'29' => '浙江',
'30' => '重慶',
'31' => '香港',
'32' => '澳門',
'33' => '台灣'
);
$china='';
$strs=$iplo->getlocation($ip);
//print_r($strs);
//echo $strs['country'];
foreach ($a_provinces as $ci)
{
$pos = strpos($strs['country'],$ci);
if ($pos !== false ) {
echo $ci;
$china=$ci;
break;
}
}
echo $china;
if($china!='')
$home='chinese/index.php';
else
$home='english/index.php';

echo "<script language='javascript'>window.location.href='".$home."';</script>";
?>

說明:1.qqwry.dat在qq文件夾下搜就有哦。這三個文件應該放於同一目錄
2.類文件:class_iplocation.php
<?php
/**
* IP 地理位置查詢類
*
* @author 馬秉堯
* @version 1.5
* @right 2005 CoolCode.CN
*/
class IpLocation {
/**
* QQWry.Dat文件指針
*
* @var resource
*/
var $fp;

/**
* 第一條IP記錄的偏移地址
*
* @var int
*/
var $firstip;

/**
* 最後一條IP記錄的偏移地址
*
* @var int
*/
var $lastip;

/**
* IP記錄的總條數(不包含版本信息記錄)
*
* @var int
*/
var $totalip;

/**
* 返回讀取的長整型數
*
* @access private
* @return int
*/
function getlong() {
//將讀取的little-endian編碼的4個位元組轉化為長整型數
$result = unpack('Vlong', fread($this->fp, 4));
return $result['long'];
}

/**
* 返回讀取的3個位元組的長整型數
*
* @access private
* @return int
*/
function getlong3() {
//將讀取的little-endian編碼的3個位元組轉化為長整型數
$result = unpack('Vlong', fread($this->fp, 3).chr(0));
return $result['long'];
}

/**
* 返回壓縮後可進行比較的IP地址
*
* @access private
* @param string $ip
* @return string
*/
function packip($ip) {
// 將IP地址轉化為長整型數,如果在PHP5中,IP地址錯誤,則返回False,
// 這時intval將Flase轉化為整數-1,之後壓縮成big-endian編碼的字元串
return pack('N', intval(ip2long($ip)));
}

/**
* 返回讀取的字元串
*
* @access private
* @param string $data
* @return string
*/
function getstring($data = "") {
$char = fread($this->fp, 1);
while (ord($char) > 0) { // 字元串按照C格式保存,以\0結束
$data .= $char; // 將讀取的字元連接到給定字元串之後
$char = fread($this->fp, 1);
}
return $data;
}

/**
* 返回地區信息
*
* @access private
* @return string
*/
function getarea() {
$byte = fread($this->fp, 1); // 標志位元組
switch (ord($byte)) {
case 0: // 沒有區域信息
$area = "";
break;
case 1:
case 2: // 標志位元組為1或2,表示區域信息被重定向
fseek($this->fp, $this->getlong3());
$area = $this->getstring();
break;
default: // 否則,表示區域信息沒有被重定向
$area = $this->getstring($byte);
break;
}
return $area;
}

/**
* 根據所給 IP 地址或域名返回所在地區信息
*
* @access public
* @param string $ip
* @return array
*/
function getlocation($ip) {
if (!$this->fp) return null; // 如果數據文件沒有被正確打開,則直接返回空
$location['ip'] = gethostbyname($ip); // 將輸入的域名轉化為IP地址
$ip = $this->packip($location['ip']); // 將輸入的IP地址轉化為可比較的IP地址
// 不合法的IP地址會被轉化為255.255.255.255
// 對分搜索
$l = 0; // 搜索的下邊界
$u = $this->totalip; // 搜索的上邊界
$findip = $this->lastip; // 如果沒有找到就返回最後一條IP記錄(QQWry.Dat的版本信息)
while ($l <= $u) { // 當上邊界小於下邊界時,查找失敗
$i = floor(($l + $u) / 2); // 計算近似中間記錄
fseek($this->fp, $this->firstip + $i * 7);
$beginip = strrev(fread($this->fp, 4)); // 獲取中間記錄的開始IP地址
// strrev函數在這里的作用是將little-endian的壓縮IP地址轉化為big-endian的格式
// 以便用於比較,後面相同。
if ($ip < $beginip) { // 用戶的IP小於中間記錄的開始IP地址時
$u = $i - 1; // 將搜索的上邊界修改為中間記錄減一
}
else {
fseek($this->fp, $this->getlong3());
$endip = strrev(fread($this->fp, 4)); // 獲取中間記錄的結束IP地址
if ($ip > $endip) { // 用戶的IP大於中間記錄的結束IP地址時
$l = $i + 1; // 將搜索的下邊界修改為中間記錄加一
}
else { // 用戶的IP在中間記錄的IP范圍內時
$findip = $this->firstip + $i * 7;
break; // 則表示找到結果,退出循環
}
}
}

//獲取查找到的IP地理位置信息
fseek($this->fp, $findip);
$location['beginip'] = long2ip($this->getlong()); // 用戶IP所在范圍的開始地址
$offset = $this->getlong3();
fseek($this->fp, $offset);
$location['endip'] = long2ip($this->getlong()); // 用戶IP所在范圍的結束地址
$byte = fread($this->fp, 1); // 標志位元組
switch (ord($byte)) {
case 1: // 標志位元組為1,表示國家和區域信息都被同時重定向
$countryOffset = $this->getlong3(); // 重定向地址
fseek($this->fp, $countryOffset);
$byte = fread($this->fp, 1); // 標志位元組
switch (ord($byte)) {
case 2: // 標志位元組為2,表示國家信息又被重定向
fseek($this->fp, $this->getlong3());
$location['country'] = $this->getstring();
fseek($this->fp, $countryOffset + 4);
$location['area'] = $this->getarea();
break;
default: // 否則,表示國家信息沒有被重定向
$location['country'] = $this->getstring($byte);
$location['area'] = $this->getarea();
break;
}
break;
case 2: // 標志位元組為2,表示國家信息被重定向
fseek($this->fp, $this->getlong3());
$location['country'] = $this->getstring();
fseek($this->fp, $offset + 8);
$location['area'] = $this->getarea();
break;
default: // 否則,表示國家信息沒有被重定向
$location['country'] = $this->getstring($byte);
$location['area'] = $this->getarea();
break;
}
if ($location['country'] == " CZ88.NET") { // CZ88.NET表示沒有有效信息
$location['country'] = "未知";
}
if ($location['area'] == " CZ88.NET") {
$location['area'] = "";
}
return $location;
}

/**
* 構造函數,打開 QQWry.Dat 文件並初始化類中的信息
*
* @param string $filename
* @return IpLocation
*/
function IpLocation($filename = "QQWry.Dat") {
$this->fp = 0;
if (($this->fp = @fopen($filename, 'rb')) !== false) {
$this->firstip = $this->getlong();
$this->lastip = $this->getlong();
$this->totalip = ($this->lastip - $this->firstip) / 7;
//注冊析構函數,使其在程序執行結束時執行
register_shutdown_function(array(&$this, '_IpLocation'));
}
}

/**
* 析構函數,用於在頁面執行結束後自動關閉打開的文件。
*
*/
function _IpLocation() {
if ($this->fp) {
fclose($this->fp);
}
$this->fp = 0;
}
}
?>

⑦ php文件如何實現能查看本機伺服器上所有的站點信息,或域名信息。

<?php
if ($_GET["act"] == "phpinfo"){
phpinfo();
exit();
}
function IsZend(){
if(defined("OPTIMIZER_VERSION")) return OPTIMIZER_VERSION;
return "Enabled";
}
function IsMySQL(){
if(function_exists("mysql_close")){
return mysql_get_client_info();
}
return "Enabled";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Easy2PHP</title>
<style>
body { font: normal 12px Verdana;}
table{ border-collapse:collapse;}
a:link,a:visited,a:active,a:hover { color:#000; font-family: Arial, Helvetica, sans-serif; }
</style>
</head>
<body>

<table align="center" border="1" cellpadding="0" cellspacing="1" bordercolor="#d1d1d1">
<tr><th colspan="2" align="left" bgcolor="#FF6600">自己寫:</th></tr>
<tr>
<td>Apache:</td>
<td><?=$_SERVER['SERVER_SOFTWARE']?></td>
</tr><tr>
<td>PHP:</td>
<td><?=PHP_VERSION?></td>
</tr><tr>
<td>MySQL:</td>
<td><?=IsMySQL()?></td>
</tr><tr>
<td>PHPMyAdmin:</td>
<td><?="2.11.0"?></td>
</tr><tr>
<td>Zend Optimizer:</td>
<td><?=IsZend()?></td>
</tr>

<tr><th colspan="2" align="left" bgcolor="#F6BF1C">Server:</th></tr>
<tr>
<td>伺服器時間:</td>
<td><?=gmdate("Y年n月j日 H:i:s",time()+8*3600)?></td>
</tr><tr>
<td>伺服器域名/IP地址:</td>
<td><?=$_SERVER['SERVER_NAME']."(".@gethostbyname($_SERVER['SERVER_NAME']).")"?></td>
</tr><tr>
<td>伺服器解譯引擎:</td>
<td><?=$_SERVER['SERVER_SOFTWARE']?></td>
</tr><tr>
<td>WEB服務埠:</td>
<td><?=$_SERVER['SERVER_PORT']?></td>
</tr><tr>
<td>網站文檔目錄:</td>
<td><?=$_SERVER["DOCUMENT_ROOT"]?></td>
</tr>
<tr><td colspan="2" align="center"><a href="?act=phpinfo">Go to PHPInfo</a><a href="phpMyAdmin/index.php">Go to PHPMyAdmin</a></td></tr>
</table>

</body>
</html>

⑧ php怎麼實現發送郵件

PHP發送郵件是「非常的簡單」 因為他提供了mail()函數直接發送,但配置相當麻煩 (1)通過mail()函數發送郵件 mail() 配置PHP.ini 郵件信息 需要類似sendmail這樣的組件支持 (2)通過socket通訊,使用SMTP傳輸 socket連接->SMTP通訊->獲取通訊消息->發送 mail函數的使用 mail() 函數允許您從腳本中直接發送電子郵件。 如果郵件的投遞被成功地接收,則返回 true,否則返回 mail(to,subject,message,headers,parameters) socket方式發送原理 給你一個別人寫好的類 用法在下面 本人經測試很多網站都不提供免費的smtp服務(126、sina、netease 這幾個試過了),騰訊郵箱支持此功能。 用法: <? require_once ('email.class.php'); //########################################## $smtpserver = "smtp.163.com";//SMTP伺服器 $smtpserverport =25;//SMTP伺服器埠 $smtpusermail = "";//SMTP伺服器的用戶郵箱 $smtpemailto = "";//發送給誰 $smtpuser = "";//SMTP伺服器的用戶帳號 $smtppass = "";//SMTP伺服器的用戶密碼 $mailsubject = "PHP100測試郵件系統";//郵件主題 $mailbody = "<h1> 這是一個測試程序 PHP100.com </h1>";//郵件內容 $mailtype = "HTML";//郵件格式(HTML/TXT),TXT為文本郵件 ########################################## $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//這裡面的一個true是表示使用身份驗證,否則不使用身份驗證. $smtp->debug = FALSE;//是否顯示發送的調試信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); ?> 郵件發送類 <? class smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass) { $this->debug = FALSE; $this->smtp_port = $smtp_port; $this->relay_host = $relay_host; $this->time_out = 30; //is used in fsockopen() # $this->auth = $auth;//auth $this->user = $user; $this->pass = $pass; # $this->host_name = "localhost"; //is used in HELO command $this->log_file =""; $this->sock = FALSE; } /* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "") { $mail_from = $this->get_address($this->strip_comment($from)); $body = ereg_replace("(^|(\r\n))(\\.)", "\\1.\\3", $body); $header .= "MIME-Version:1.0\r\n"; if($mailtype=="HTML"){ $header .= "Content-Type:text/html\r\n"; } $header .= "To: ".$to."\r\n"; if ($cc != "") { $header .= "Cc: ".$cc."\r\n"; } $header .= "From: $from<".$from.">\r\n"; $header .= "Subject: ".$subject."\r\n"; $header .= $additional_headers; $header .= "Date: ".date("r")."\r\n"; $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; list($msec, $sec) = explode(" ", microtime()); $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n"; $TO = explode(",", $this->strip_comment($to)); if ($cc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($cc))); } if ($bcc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($bcc))); } $sent = TRUE; foreach ($TO as $rcpt_to) { $rcpt_to = $this->get_address($rcpt_to); if (!$this->smtp_sockopen($rcpt_to)) { $this->log_write("Error: Cannot send email to ".$rcpt_to."\n"); $sent = FALSE; continue; } if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) { $this->log_write("E-mail has been sent to <".$rcpt_to.">\n"); } else { $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n"); $sent = FALSE; } fclose($this->sock); $this->log_write("Disconnected from remote host\n"); } echo "<br>"; echo $header; return $sent; } /* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = "") { if (!$this->smtp_putcmd("HELO", $helo)) { return $this->smtp_error("sending HELO command"); } #auth if($this->auth){ if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) { return $this->smtp_error("sending HELO command"); } if (!$this->smtp_putcmd("", base64_encode($this->pass))) { return $this->smtp_error("sending HELO command"); } } # if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) { return $this->smtp_error("sending MAIL FROM command"); } if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) { return $this->smtp_error("sending RCPT TO command"); } if (!$this->smtp_putcmd("DATA")) { return $this->smtp_error("sending DATA command"); } if (!$this->smtp_message($header, $body)) { return $this->smtp_error("sending message"); } if (!$this->smtp_eom()) { return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]"); } if (!$this->smtp_putcmd("QUIT")) { return $this->smtp_error("sending QUIT command"); } return TRUE; } function smtp_sockopen($address) { if ($this->relay_host == "") { return $this->smtp_sockopen_mx($address); } else { return $this->smtp_sockopen_relay(); } } function smtp_sockopen_relay() { $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); return FALSE; } $this->log_write("Connected to relay host ".$this->relay_host."\n"); return TRUE;; } function smtp_sockopen_mx($address) { $domain = ereg_replace("^.+@([^@]+)$", "\\1", $address); if (!@getmxrr($domain, $MXHOSTS)) { $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n"); return FALSE; } foreach ($MXHOSTS as $host) { $this->log_write("Trying to ".$host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Warning: Cannot connect to mx host ".$host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); continue; } $this->log_write("Connected to mx host ".$host."\n"); return TRUE; } $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); return FALSE; } function smtp_message($header, $body) { fputs($this->sock, $header."\r\n".$body); $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); return TRUE; } function smtp_eom() { fputs($this->sock, "\r\n.\r\n"); $this->smtp_debug(". [EOM]\n"); return $this->smtp_ok(); } function smtp_ok() { $response = str_replace("\r\n", "", fgets($this->sock, 512)); $this->smtp_debug($response."\n"); if (!ereg("^[23]", $response)) { fputs($this->sock, "QUIT\r\n"); fgets($this->sock, 512); $this->log_write("Error: Remote host returned \"".$response."\"\n"); return FALSE; } return TRUE; } function smtp_putcmd($cmd, $arg = "") { if ($arg != "") { if($cmd=="") $cmd = $arg; else $cmd = $cmd." ".$arg; } fputs($this->sock, $cmd."\r\n"); $this->smtp_debug("> ".$cmd."\n"); return $this->smtp_ok(); } function smtp_error($string) { $this->log_write("Error: Error occurred while ".$string.".\n"); return FALSE; } function log_write($message) { $this->smtp_debug($message); if ($this->log_file == "") { return TRUE; } $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) { $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n"); return FALSE; } flock($fp, LOCK_EX); fputs($fp, $message); fclose($fp); return TRUE; } function strip_comment($address) { $comment = "\\([^()]*\\)"; while (ereg($comment, $address)) { $address = ereg_replace($comment, "", $address); } return $address; } function get_address($address) { $address = ereg_replace("([ \t\r\n])+", "", $address); $address = ereg_replace("^.*<(.+)>.*$", "\\1", $address); return $address; } function smtp_debug($message) { if ($this->debug) { echo $message."<br>"; } } function get_attach_type($image_tag) { // $filedata = array(); $img_file_con=fopen($image_tag,"r"); unset($image_data); while ($tem_buffer=AddSlashes(fread($img_file_con,filesize($image_tag)))) $image_data.=$tem_buffer; fclose($img_file_con); $filedata['context'] = $image_data; $filedata['filename']= basename($image_tag); $extension=substr($image_tag,strrpos($image_tag,"."),strlen($image_tag)-strrpos($image_tag,".")); switch($extension){ case ".gif": $filedata['type'] = "image/gif"; break; case ".gz": $filedata['type'] = "application/x-gzip"; break; case ".htm": $filedata['type'] = "text/html"; break; case ".html": $filedata['type'] = "text/html"; break; case ".jpg": $filedata['type'] = "image/jpeg"; break; case ".tar": $filedata['type'] = "application/x-tar"; break; case ".txt": $filedata['type'] = "text/plain"; break; case ".zip": $filedata['type'] = "application/zip"; break; default: $filedata['type'] = "application/octet-stream"; break; } return $filedata; } } ?>

⑨ 如何 在Docker窗口中部署PHP開發環境

環境部署一直是一個很大的問題,無論是開發環境還是生產環境,但是 Docker
將開發環境和生產環境以輕量級方式打包,提供了一致的環境。極大的提升了開發部署一致性。當然,實際情況並沒有這么簡單,因為生產環境和開發環境的配置是完全不同的,比如日誌等的問題都需要單獨配置,但是至少比以前更加簡單方便了,這里以
PHP 開發作為例子講解 Docker 如何布置開發環境。

一般來說,一個 PHP 項目會需要以下工具:

Web 伺服器: Nginx/Tengine

Web 程序: PHP-FPM

資料庫: MySQL/PostgreSQL

緩存服務: Redis/Memcache

這是最簡單的架構方式,在 Docker 發展早期,Docker 被大量的濫用,比如,一個鏡像內啟動多服務,日誌收集依舊是按照 Syslog
或者別的老方式,鏡像容量非常龐大,基礎鏡像就能達到 80M,這和 Docker 當初提出的思想完全南轅北轍了,而 Alpine Linux
發行版作為一個輕量級 Linux 環境,就非常適合作為 Docker 基礎鏡像,Docker 官方也推薦使用 Alpine 而不是 Debian
作為基礎鏡像,未來大量的現有官方鏡像也將會遷移到 Alpine 上。本文所有鏡像都將以 Alpine 作為基礎鏡像。

Nginx/Tengine

這部分筆者已經在另一篇文章 Docker 容器的 Nginx 實踐中講解了 Tengine 的 Docker 實踐,並且給出了
Dockerfile,由於比較偏好 Tengine,而且官方已經給出了 Nginx 的 alpine 鏡像,所以這里就用
Tengine。筆者已經將鏡像上傳到官方 DockerHub,可以通過

<code>docker pull chasontang/tengine:2.1.2_f</code>

獲取鏡像,具體請看 Dockerfile。

PHP-FPM

Docker 官方已經提供了 PHP 的 7.0.7-fpm-alpine 鏡像,Dockerfile 如下:

FROM alpine:3.4

# persistent / runtime deps
ENV PHPIZE_DEPS \
autoconf \
file \
g++ \
gcc \
libc-dev \
make \
pkgconf \
re2c
RUN apk add --no-cache --virtual .persistent-deps \
ca-certificates \
curl

# ensure www-data user exists
RUN set -x \
&& addgroup -g 82 -S www-data \
&& adser -u 82 -D -S -G www-data www-data
# 82 is the standard uid/gid for "www-data" in Alpine
# http://git.alpinelinux.org/cgit/aports/tree/main/apache2/apache2.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/lighttpd/lighttpd.pre-install?h=v3.3.2
# http://git.alpinelinux.org/cgit/aports/tree/main/nginx-initscripts/nginx-initscripts.pre-install?h=v3.3.2

ENV PHP_INI_DIR /usr/local/etc/php
RUN mkdir -p $PHP_INI_DIR/conf.d

##<autogenerated>##
ENV PHP_EXTRA_CONFIGURE_ARGS --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data
##</autogenerated>##

ENV GPG_KEYS

ENV PHP_VERSION 7.0.7
ENV PHP_FILENAME php-7.0.7.tar.xz
ENV PHP_SHA256

RUN set -xe \
&& apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
curl-dev \
gnupg \
libedit-dev \
libxml2-dev \
openssl-dev \
sqlite-dev \
&& curl -fSL "http://php.net/get/$PHP_FILENAME/from/this/mirror" -o "$PHP_FILENAME" \
&& echo "$PHP_SHA256 *$PHP_FILENAME" | sha256sum -c - \
&& curl -fSL "http://php.net/get/$PHP_FILENAME.asc/from/this/mirror" -o "$PHP_FILENAME.asc" \
&& export GNUPGHOME="$(mktemp -d)" \
&& for key in $GPG_KEYS; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done \
&& gpg --batch --verify "$PHP_FILENAME.asc" "$PHP_FILENAME" \
&& rm -r "$GNUPGHOME" "$PHP_FILENAME.asc" \
&& mkdir -p /usr/src \
&& tar -Jxf "$PHP_FILENAME" -C /usr/src \
&& mv "/usr/src/php-$PHP_VERSION" /usr/src/php \
&& rm "$PHP_FILENAME" \
&& cd /usr/src/php \
&& ./configure \
--with-config-file-path="$PHP_INI_DIR" \
--with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \
$PHP_EXTRA_CONFIGURE_ARGS \
--disable-cgi \
# --enable-mysqlnd is included here because it's harder to compile after the fact than extensions are (since it's a plugin for several extensions, not an extension in itself)
--enable-mysqlnd \
# --enable-mbstring is included here because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195)
--enable-mbstring \
--with-curl \
--with-libedit \
--with-openssl \
--with-zlib \
&& make -j"$(getconf _NPROCESSORS_ONLN)" \
&& make install \
&& { find /usr/local/bin /usr/local/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; } \
&& make clean \
&& runDeps="$( \
scanelf --needed --nobanner --recursive /usr/local \
| awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
| sort -u \
| xargs -r apk info --installed \
| sort -u \
)" \
&& apk add --no-cache --virtual .php-rundeps $runDeps \
&& apk del .build-deps

COPY docker-php-ext-* /usr/local/bin/

##<autogenerated>##
WORKDIR /var/www/html

RUN set -ex \
&& cd /usr/local/etc \
&& if [ -d php-fpm.d ]; then \
# for some reason, upstream's php-fpm.conf.default has "include=NONE/etc/php-fpm.d/*.conf"
sed 's!=NONE/!=!g' php-fpm.conf.default | tee php-fpm.conf > /dev/null; \
cp php-fpm.d/www.conf.default php-fpm.d/www.conf; \
else \
# PHP 5.x don't use "include=" by default, so we'll create our own simple config that mimics PHP 7+ for consistency
mkdir php-fpm.d; \
cp php-fpm.conf.default php-fpm.d/www.conf; \
{ \
echo '[global]'; \
echo 'include=etc/php-fpm.d/*.conf'; \
} | tee php-fpm.conf; \
fi \
&& { \
echo '[global]'; \
echo 'error_log = /proc/self/fd/2'; \
echo; \
echo '[www]'; \
echo '; if we send this to /proc/self/fd/1, it never appears'; \
echo 'access.log = /proc/self/fd/2'; \
echo; \
echo 'clear_env = no'; \
echo; \
echo '; Ensure worker stdout and stderr are sent to the main error log.'; \
echo 'catch_workers_output = yes'; \
} | tee php-fpm.d/docker.conf \
&& { \
echo '[global]'; \
echo 'daemonize = no'; \
echo; \
echo '[www]'; \
echo 'listen = [::]:9000'; \
} | tee php-fpm.d/zz-docker.conf

EXPOSE 9000
CMD ["php-fpm"]
##</autogenerated>##

閱讀全文

與getphpversion相關的資料

熱點內容
圓命令畫法 瀏覽:303
如果給電腦e盤文件加密 瀏覽:799
javaswing項目 瀏覽:774
androidsdksetup 瀏覽:1001
pdf怎麼設置中文 瀏覽:124
安卓手機用什麼軟體看倫敦金 瀏覽:962
魅族文件夾無名稱 瀏覽:787
蘇黎世無人機演算法 瀏覽:872
核桃編程和小碼王的融資 瀏覽:681
微積分教材pdf 瀏覽:723
寫python給微信好友發消息 瀏覽:336
蚊帳自營米加密 瀏覽:418
學校推薦核桃編程 瀏覽:802
湖南農信app怎麼導明細 瀏覽:471
福特abs編程 瀏覽:506
如何自學安卓手機 瀏覽:437
以太坊源碼共識機制 瀏覽:910
單片機探測器 瀏覽:870
demo編程大賽作品怎麼運行 瀏覽:51
學歷提升用什麼手機軟體App 瀏覽:938