exportphp
⑴ Linux系统中设置多版本php共存配合Nginx服务器使用
应用环境
LNMP的环境,当前PHP版本5.3.8,遇到一个应用需求只支持PHP
5.2.x,又希望保持现有应用还是用PHP
5.3.8。也就是说需要两个版本的PHP同时存在,供nginx根据需要调用不同版本。
思路
Nginx是通过PHP-FastCGI与PHP交互的。而PHP-FastCGI运行后会通过文件、或本地端口两种方式进行监听,在Nginx中配置相应的FastCGI监听端口或文件即实现Nginx请求对PHP的解释。
既然PHP-FastCGI是监听端口和文件的,那就可以让不同版本的PHP-FastCGI同时运行,监听不同的端口或文件,Nginx中根据需求配置调用不同的PHP-FastCGI端口或文件,即可实现不同版本PHP共存了。
配置记录
下面记录简单的配置流程,基于已经安装了lnmp的debian环境。当前版本的PHP是5.3.8,位于/usr/local/php。
1.下载PHP-5.2.14及相关的FPM、autoconf组件:
mkdir
~/php5.2
cd
~/php5.2
wget
-c
http://museum.php.net/php5/php-5.2.14.tar.gz
wget
-c
http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
2.解压PHP-5.2.14,并打上PHP-FPM的补丁:
tar
zxvf
php-5.2.14.tar.gz
gzip
-cd
php-5.2.14-fpm-0.5.14.diff.gz
|
patch
-d
php-5.2.14
-p1
3.如果你已经通过lnmp安装,应该已经安装好了autoconf,如果没有,请自行下载并编译autoconf-2.13,然后设置autoconf环境变量:
export
PHP_AUTOCONF=/usr/local/autoconf-2.13/bin/autoconf¬
export
PHP_AUTOHEADER=/usr/local/autoconf-2.13/bin/autoheader
3.编译安装PHP-5.2.14在新的路径(/usr/local/php-5.2.14)下,注意–prefix、–with-config-file-path的路径,并且打开fastcgi和fpm选项:
cd
php-5.2.14/
./buildconf
--force
./configure
--prefix=/usr/local/php-5.2.14
--with-config-file-path=/usr/local/php-5.2.14/etc
--with-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
--enable-fastcgi
--enable-fpm
make
ZEND_EXTRA_LIBS='-liconv'
make
install
4.设置/usr/local/php-5.2.14/etc/php-fpm.conf,监听端口:
<value
name="listen_address">127.0.0.1:9001</value>
或者监听文件:
<value
name="listen_address">/path/to/unix/socket</value>
其他参数根据服务器环境和需求自行定制。
5.启动php-fpm,以后可以通过php-fpm进行管理:
/usr/local/php-5.2.14/sbin/php-fpm
start
字php5.3.3后,php已经将php-fpm继承到php中,而且内置的php-fpm默认不支持(start|stop|reload)的平滑启动参数,需要使用官方源代码中提供的启动脚本来控制:
cp
-f
(php
-5.3.x-source-dir)/sapi/fpm/init.d.php-fpm
/etc/init.d/php-fpm
chmod
755
/etc/init.d/php-fpm
/etc/init.d/php-fpm
start
php-fpm支持的操作:
start,启动PHP的FastCGI进程。
stop,强制终止PHP的FastCGI进程。
quit,平滑终止PHP的FastCGI进程。
restart,
重启PHP的FastCGI进程。
reload,
重新加载PHP的php.ini。
logrotate,
重新启用log文件。
5.3.3的php-fpm脚本支持的操作:start|stop|force-quit|restart|reload|status
6.配置好PHP-5.2.14的php.ini,重新加载生效:
vi
/usr/local/php-5.2.14/etc/php.ini
/usr/local/php-5.2.14/sbin/php-fpm
reload
7.修改nginx配置,对需要的服务配置使用PHP-5.2.14:
location
~
.*.(php|php5)?$
{
fastcgi_pass
127.0.0.1:9001;
fastcgi_index
index.php;
include
fcgi.conf;
}
8.记录一下自己编译php5.5.10使用的配置
./configure
--prefix=/usr/local/php-5.5.10
--with-config-file-path=/usr/local/php-5.5.10/etc
--with-mysql=mysqlnd
--with-mysqli=mysqlnd
--with-bz2
--with-curl=/usr/bin
--enable-ftp
--enable-sockets
--disable-ipv6
--with-gd
--with-jpeg-dir=/usr/local
--with-png-dir=/usr/local
--with-freetype-dir=/usr/local
--enable-gd-native-ttf
--with-iconv-dir=/usr/local
--enable-mbstring
--enable-calendar
--with-gettext
--with-libxml-dir=/usr/local
--with-zlib
--with-pdo-mysql=mysqlnd
--enable-dom
--enable-xml
--enable-fpm
--with-libdir=lib64
--with-mcrypt=/usr/bin
--enable-zip
--enable-soap
--enable-mbstring
--with-gd
--with-openssl
--enable-pcntl
--with-xmlrpc
--enable-opcache
⑵ mysql字符串转换成字典
mysql字符串转换成字典可以用php数据表转换成数据字典的程序。网上找到别人写好的php数据表转换成卜洞数据字典的程序export2.php,型高枯修改export2.php中连接数据库的信息(数据库IP、念燃数据库名称、访问数据库的账号密码。
⑶ PHP中var_mp是什么意思
var_mp 是PHP中的调试函数,可以用var_mp打印所有的对象,查看对象内部的数据结构。
python 中如果提前定义了__str__函数,可以使用print str(object)这种方式打印对象内容。
void var_mp ( mixed $expression [, mixed $... ] )
此函数显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。
In PHP 5 all public, private and protected properties of objects will be returned in the output.
Tip
和直接将结果输出到浏览器一样,可使用输出控制函数来捕获当前函数的输出,然后(例如)保存到一个 string中。
拓展资料:
var_mp()方法,判断一个变量的类型与长度,并输出变量的数值,如果变量有值,则输出是变量的值,并返回数据类型。
显示关于一个或多个表达式的结构信息,包括表达式的类型与值。数组将递归展开值,通过缩进显示其结构。
格式:var_mp ( mixed expression [, mixed expression [, ...]] )
语法:
var_mp (var,var,bar);
注意:
用保证var_mp中的变量必须是存在的,如果变量存在但值是空,则返回false;
没有变量时,则返回NULL。
该函数有输出的功能,因此不必加其它的输出函数。
⑷ PHP中怎么用代码实现文件下载
CI框架:
前台:a.php <a href="download/export">download</a>
后台:download.php
function export(){
//把js,css的路径文件名填充下面的$url和$fname就可以了
//至于html文件,先在后台生成一个html文件,然后下载就可以了
$fname=date('YmdHis').'.xls';
$url='./xls/'.$fname;
$this->excel_m->write($url);
$file = fopen($url,"r"); // 打开文件
// 输入文件标签
header('Content-Encoding: utf-8');
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($url));
header('Content-Transfer-Encoding: binary' );
header("Content-Disposition: attachment; filename=" .$fname); //以真实文件名提供给浏览器下载
header('Pragma: no-cache');
header('Expires: 0');
//输出文件内容
echo fread($file,filesize($url));
fclose($file);
}