Author Archives: tommy

远程调用SHELL函数

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; }

Posted in 学习笔记 | Leave a comment

PHP获取文件权限函数

// 获取权限 function getChmod($filepath){ return substr(base_convert(@fileperms($filepath),10,8),-4); }

Posted in 学习笔记 | Leave a comment

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); } … Continue reading

Posted in 学习笔记 | Leave a comment

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对外宣称的:操作简单,运行高效。

Posted in 学习笔记 | 2 Comments

关于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次 … Continue reading

Posted in 学习笔记 | Tagged , , , , | 5 Comments

使用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;

Posted in 我的代码 | Tagged | Leave a comment

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 … Continue reading

Posted in 学习笔记 | Tagged , , | Leave a comment

常用的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 … Continue reading

Posted in 学习笔记 | Tagged , | Leave a comment

关于DoitPHP的性能测试

自DoitPHP对外发布以来,首次进行对DoitPHP与其它PHP框架进行性能对比测试 测试数据如下:http://bbs.doitphp.com/thread-6-1-1.html (注:文章中有截图,需注册才能看到)。 关于DoitPHP的命名。Doit = do + it, 来源于某公司的广告词:“JUST DO IT”。

Posted in 学习笔记 | Tagged | 2 Comments

mysql社区版服务器5.5.14发布

mysql官方网站发布了mysql社区版服务器的最新版本,5.5.14 下载地址: http://www.mysql.com/downloads/mysql/

Posted in 学习笔记 | Tagged | Leave a comment