导航:首页 > 编程语言 > 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相关的资料

热点内容
三台服务器配置IP地址 浏览:171
如何用命令方块连续对话 浏览:274
win7linux共享文件夹 浏览:301
命令符打开本地服务 浏览:597
android应用程序源码 浏览:699
安卓开发工程师简历怎么写 浏览:57
热水器水量服务器是什么意思 浏览:115
stk卫星编译 浏览:477
对后台程序员的要求 浏览:758
ios大文件夹图标 浏览:624
生的计划pdf 浏览:711
oppoa93加密便签在哪查找 浏览:19
两个数字的加减乘除运算编程 浏览:227
给手机加密码忘记了怎么办 浏览:601
单片机运算符 浏览:297
移动端微信商城源码 浏览:443
编程猫下一个背景在哪里 浏览:358
javaclasstype 浏览:239
乐高编程和乐高课的延伸 浏览:357
苹果手机怎么切换app美国账号 浏览:865