function remoteRunShell($ip, $shell, $sysuser, $syspass) {
$connection = ssh2_connect($ip, 22);
if(!ssh2_auth_password($connection, $sysuser, $syspass)) {
return false;
}
$stream = ssh2_exec($connection, $shell);
stream_set_blocking($stream, true);
$output = stream_get_contents($stream);
fclose($stream);
return $output;
}
远程调用SHELL函数
PHP获取文件权限函数
// 获取权限
function getChmod($filepath){
return substr(base_convert(@fileperms($filepath),10,8),-4);
}
PHP执行系统命令函数
function execute($cfe) {
$res = ”;
if ($cfe) {
if(function_exists(‘system’)) {
@ob_start();
@system($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(function_exists(‘passthru’)) {
@ob_start();
@passthru($cfe);
$res = @ob_get_contents();
@ob_end_clean();
} elseif(function_exists(‘shell_exec’)) {
$res = @shell_exec($cfe);
} elseif(function_exists(‘exec’)) {
@exec($cfe,$res);
$res = join(“\n”,$res);
} elseif(@is_resource($f = @popen($cfe,”r”))) {
$res = ”;
while(!@feof($f)) {
$res .= @fread($f,1024);
}
@pclose($f);
}
}
return $res;
}
DoitPHP新版本将不支持ActiveRecord
昨晚研究了一个晚上的ActiveRecord..,看了许多知名的框架..国外的居多。自己也写了好多ActiveRecord程序在doitphp中的应用..一进行效率测试就直接拿掉了。原想新的doitphp支持下ActiveRecord来着,一来显示doitphp的功能强大..二来免得有人说doitphp不支持ActiveRecord等。现在坚定了我的信念:doitphp下一个版本还是不支持ActiveRecord的。如果我们没有找到一个简单高效的方法来处理这块..doitphp就会永不会支持。
doitphp不支持ActiveRecord原因有三:
1、从PHP语言本身的性质而言,ActiveRecord纯是花拳秀腿..运行效率慢..非常不实用。
2、ActiveRecord进行数据操作非常不灵活。对于新手入门难度高。像那些运用ActiveRecord的框架在给出的demo上,都是理想化的数据操作..在项目开发中这种理想化的数据操作情况出现机率很小。如果进行复杂点的处理直接就悲剧了。入门难度高则会使新手直接不使用这功能..框架加了这个功能也等于白加。
3、doitphp在处理多数据表的关联操作时,有更好的解决办法..在model层自定义业务逻辑(当然其它框架也有这个功能)..一来灵活,二来操作简单,三来运行高效。有人说使用ActiveRecord可以快速的开发程序..这个不假,可是对于那些熟练使用的人来说..使用情况也很有局限性。用自定义业务逻辑无非就是在model层多写几行代码..开发效率也慢不了哪里..问题是这样做来的极为方便,再复杂的数据处理也完全可以满足需要。这正是doitphp对外宣称的:操作简单,运行高效。
关于doitphp,thinkphp,yii,ci,doophp等框架的性能对比测试
“Never guess, Get data”翻译成中国话就是:“不要胡乱猜测,拿出数据来证明”。前几天对常用的PHP框架进行了对比测试。内容如下:
测试环境:
硬件环境:
THINKPAD T61笔记本
CPU:INTEL CORE(TM2) DUO T770
内存:2G
硬盘:320G 7200
显卡:集成显卡
软件环境:
操作系统:win 2003 sp2
PHP环境:Apache/2.2.17 (Win32) PHP/5.3.6
数据库:mysql 5.5.10
测试工具:apache bench (即:ab)
测试内容:ab -c 10 -n 1000 测试网址
让这些框架从同一个数据库,同一个数据表读出1000条数据,并在视图中显示出来,且视图采用视图渲染(即:layout和widget应用)。保证最后输出页面内容相同(HTML完全一样)。
测试结果:
1、原生php:

注:上图测试数据是500次的测试数据,在测试1000时,由于系统报错,故测试了500次。
所用时间:2.032秒(1.016*2)
平均每秒请求次数:492.31次
平均每次请求所用时间:20.313毫秒
2、doitphp:
测试版本:1.0

所用时间:5.750秒
平均每秒请求次数:173.91次
平均每次请求所用时间:57.500毫秒
(是原生PHP运行效率的35.3%)
3、thinkphp
测试版本:2.1

所用时间:11.797秒
平均每秒请求次数:84.77次
平均每次请求所用时间:117.969毫秒
(是原生PHP运行效率的17.2%)
4、codeigniter
测试版本:2.0.2

所用时间:15.266秒
平均每秒请求次数:65.51次
平均每次请求所用时间:152.656毫秒
(是原生PHP运行效率的13.3%)
5、yii framework
测试版本:1.1.8

所用时间:26.328秒
平均每秒请求次数:37.98次
平均每次请求所用时间:263.281毫秒
(是原生PHP运行效率的7.7%)
6、doophp
测试版本:1.4.1

所用时间:14.484秒
平均每秒请求次数:69.04次
平均每次请求所用时间:144.844毫秒
(是原生PHP运行效率的14.0%)
7、qeephp
测试版本:2.1.2560

所用时间:24.609秒
平均每秒请求次数:40.63次
平均每次请求所用时间:246.094毫秒
(是原生PHP运行效率的8.3%)
结论:
在综合应用上,DoitPHP运行效率分别是:
原生PHP的 35.3%,
是thinkphp 2.1 的2.1倍
是codeigniter 2.0.2的2.6倍
是doophp 1.4.1的2.5倍
是yii 1.1.8的4.5倍
是qeephp 2.1.2560的4.3倍。
使用PHP下载文件
使用PHP下载文件方法很多,比较常用的就是使用函数:readfile。演示代码如下:
代码一:
header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename=’.basename($file_path));
header(‘Content-Transfer-Encoding: binary’);
header(‘Expires: 0′);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header(‘Pragma: public’);
header(‘Content-Length: ‘ . filesize($file_path));
readfile($file_path);
代码二:
$fileinfo = pathinfo($thefile);
header(‘Content-type: application/x-’.$fileinfo['extension']);
header(‘Content-Disposition: attachment; filename=’.$fileinfo['basename']);
header(‘Content-Length: ‘.filesize($thefile));
readfile($thefile);
exit;
centos上安装php运行环境(手记)
-, 配置apache
1.关闭防火墙
service iptables stop
chkconfig iptables off
2.开启apache
service httpd status
service httpd start
3.更改http.conf配置
ServerTokens OS –> ServerTokens Prod
ServerSignature On –> ServerSignature Off
DirectoryIndex index.html index.html.var
–>
DirectoryIndex index.html index.php
更改管理员邮箱
#ServerName new.host.name:80 –> 根据需要自行修改
Options Indexes FollowSymLinks –> Options Includes ExecCGI FollowSymLinks
#AddHandler cgi-script .cgi –> AddHandler cgi-script .cgi .pl
AllowOverride None -> AllowOverride All
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined
–>
LogFormat “%h %l %u %t \”%!414r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined
Options Indexes MultiViews –> Options MultiViews
却掉apache的测试页
rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html
chkconfig httpd on
chkconfig –list httpd
二,配置php
1.新建php测试页
echo ‘<?php phpinfo();’ > /var/www/html/index.php
2.升级php 5.1.6 -> 5.2.16
rpm –import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
vim /etc/yum.repos.d/CentOS-Base.repo
添加内容:
[utterramblings]
name=Jason’s Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
yum -y update php
yum -y install libmcrypt
yum -y install php-mcrypt
yum -y install php-gd
yum -y install php-soap
yum -y install php-json
yum -y install php-mbstring
安装zend-opterate
cd /usr/local/src
wget http://downloads.zend.com/optimizer/3.3.3/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
tar zxvf ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
cd ZendOptimizer-3.3.3-linux-glibc23-i386
./install.sh
cd ../
rm -rf ZendOptimizer*
三,配置mysql
yum install mysql
yum -y install mysql-server
yum install mysql-devel
chgrp -R mysql /var/lib/mysql
chmod -R 770 /var/lib/mysql
service mysqld start
yum -y install php-mysql
service httpd restart
vim /etc/my.cnf
添加
default-character-set = utf8
[mysql]
default-character-set = utf8
chkconfig mysqld on
chkconfig –list mysqld
设置密码
mysql -u root
select user,host,password from mysql.user;
set password for root@localhost=password(’123456′);
set password for root@127.0.0.1=password(’123456′);
set password for root@All-STAR=password(’123456′);
常用的HTTP 状态
header('HTTP/1.1 404 Not Found');
header('HTTP/1.1 403 Access forbidden');
常用的HTTP 状态列表:
100 : Continue, 101 : Switching Protocols, 102 : Processing, 200 : OK, 201 : Created, 202 : Accepted, 203 : Non-Authoritative Information, 204 : No Content, 205 : Reset Content, 206 : Partial Content, 207 : Multi-Status, 226 : IM Used, 300 : Multiple Choices, 301 : Moved Permanently, 302 : Found, 303 : See Other, 304 : Not Modified, 305 : Use Proxy, 306 : Reserved, 307 : Temporary Redirect, 400 : Bad Request, 401 : Unauthorized, 402 : Payment Required, 403 : Forbidden, 404 : Not Found, 405 : Method Not Allowed, 406 : Not Acceptable, 407 : Proxy Authentication Required, 408 : Request Timeout, 409 : Conflict, 410 : Gone, 411 : Length Required, 412 : Precondition Failed, 413 : Request Entity Too Large, 414 : Request-URI Too Long, 415 : Unsupported Media Type, 416 : Requested Range Not Satisfiable, 417 : Expectation Failed, 422 : Unprocessable Entity, 423 : Locked, 424 : Failed Dependency, 426 : Upgrade Required, 500 : Internal Server Error, 501 : Not Implemented, 502 : Bad Gateway, 503 : Service Unavailable, 504 : Gateway Timeout, 505 : HTTP Version Not Supported, 506 : Variant Also Negotiates, 507 : Insufficient Storage, 510 : Not Extended
关于DoitPHP的性能测试
自DoitPHP对外发布以来,首次进行对DoitPHP与其它PHP框架进行性能对比测试
测试数据如下:http://bbs.doitphp.com/thread-6-1-1.html (注:文章中有截图,需注册才能看到)。
关于DoitPHP的命名。Doit = do + it, 来源于某公司的广告词:“JUST DO IT”。
mysql社区版服务器5.5.14发布
mysql官方网站发布了mysql社区版服务器的最新版本,5.5.14
下载地址:
http://www.mysql.com/downloads/mysql/