Saturday, January 24, 2009

脚本执行速度测试简单实现

之前看到有人测试脚本执行时间,在程序开始的时候计一个时间,再到程序最后再计一次时间,从而得到脚本的执行时间。但如果脚本是从其它的分支退出,那又得再写一次。

我觉得这样不方便,退出分支多的时候,代码就散开不好管理了,而解决方案就是下面的:


$jacky_test_time = microtime(true);
function jacky_test_tf($ff=”) { global $jacky_test_time; $result = microtime(true)-$jacky_test_time; echo “”; }
register_shutdown_function(’jacky_test_tf’);


当然在程序当中的任何位置都可以调用 jacky_test_tf 函数去输出执行到当前的时间。

a simple way to get your PHP script if running in CLI

There is a function to get that way easier.

public static function inCli() {
return php_sapi_name() == ‘cli’;
}

Zend Studio远程调试PHP再整理

1.下载Debug:
http://downloads.zend.com/pdt/server-debugger/

2.将压缩包中的5_2_x_comp中的ZendDebugger.dll解压到新建目录:
C:\Program Files\Zend\ZendDebugger-5.2.14\php-5.2.x

3.安装Zend Optimize或下载Zend Extension Manager.dll

4.修改php.ini(新增)(根据自己的情况对路径做修改)
zend_extension_ts="C:\Program Files\Zend\ZendExtensionManager.dll"
zend_extension_manager.debug_server_ts="C:\Program Files\Zend\ZendDebugger-5.2.14"
zend_debugger.expose_remotely=allowed_hosts
zend_debugger.allow_hosts=127.0.0.1/32,192.168.1.0/16
zend_debugger.allow_tunnel=127.0.0.1/32

5.解压debug压缩包里的dummy.php到要调试的网站根目录。

6.重启Web server.

———————–热情分割线———————–

另外,配置也可参考这个不用ZO的:
zend_extension_ts=”D:/Servers/php5/ext/ZendDebugger.dll”
zend_debugger.allow_hosts=192.168.1.1
zend_debugger.expose_remotely=always

解决在浏览器中光标丢失的问题。

现象就是文本框中的光标没有了。

原因(只能说是原因之一)就是用Javascript捕获了blur事件而没有返回true导致的。

解决办法:在捕获blur事件返回true即可。

例子(JQuery):

$(’.text’).blur(function() {
//alert($(this).attr(’sid’));
this.value=$(this).attr(’sid’);
return true;
});

结束。

基于Web的iPhone App设置桌面显示图标的方法

用Safari可以将一个Web页收藏到桌面,就形成了一个桌面图标,而这个图标不适用你的网站原来的 favicon.ico 了,所以需要重新指定一个iPhone桌面专用的图标,只要在网站首页面内的head中添加一个link即解决,如下:



重新收藏到桌面图标即可更新。

解决在虚拟主机中使用Zend Framework时,根目录不能指定的问题

标题好长,因为问题不太好描述,但又是在虚拟主机中使用ZF常见的问题。
通常使用ZF时,根目录都指定到只有一个index.php的目录html,(也可以叫别的名字,参考:http://framework.zend.com/manual/en /zend.controller.html#zend.controller.quickstart.go),其它目录如applications和 library都与这个目录同级,但在虚拟主机环境下,根目录是固定的,你不能把ZF的application和library放到根目录的上级目录里去。如果把application和library放到html目录,即窝囊又可能造成路径问题。
其实这个问题又重写规则解决比较简单,.htaccess文件内容参考如下修改:

—————————代表月亮消灭你分割线————————————

RewriteEngine on

RewriteRule ^(images/.+) /html/$1 [L] #修正图片请求,根据自己的目录来。
RewriteRule ^(css/.+) /html/$1 [L]
RewriteRule ^(jscript/.+) /html/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /html/index.php #其它找不到存在文件的请求全部转到html目录下的入口index.php

—————————-代表月亮消灭你分割线———————————–

这样问题就解决了,但又有一个新问题就是application和library目录下的文件可能会被用户访问到(直接url干进去),所以这个.htaccess文件可以再修改一下,针对deny的目录设置一下即可。

a Regexp testing :)

一串很长的数字,请对这个字字中每三位间加一个逗号(从右加)。
原:
12345678901234567890
目标:
12,345,678,901,234,567,890

答案在下面,反白显示:

Find:

((?<=\d)(\d){3}\b)

Replace with:

Saving time Tips1: Emeditor & Regexp

Original text:

a1,
p1,
t1,
a2,
p2,
t2,
price,
p3,
period,
bt,


Objective text:

$a1 = $_POST[”a1″];
$p1 = $_POST[”p1″];
$t1 = $_POST[”t1″];
$a2 = $_POST[”a2″];
$p2 = $_POST[”p2″];
$t2 = $_POST[”t2″];
$price = $_POST[”price”];
$p3 = $_POST[”p3″];
$period = $_POST[”period”];
$bt = $_POST[”bt”];


Tool: Emeditor

Using regexp replace:

Find:

(.*),

Replace with:

$\1 = $_POST[”\1″];

-------------------------------------

Emeditor also has Macro function, what the fucking it easy to being.

Setup Basic authentication on Lighttpd

Simply, I picked plain text file to save password, of course there are httpasswd and htdigest for the password saving.


auth.backend = “plain”
auth.backend.plain.userfile = “/home/pathsomething/lighttpd.user”

auth.backend = “plain”
auth.require = ( “/mysql/” =>
(
“method” => “digest”,
“realm” => “mysql”,
“require” => “valid-user”
)
)


The password file is just like this:


username:passwd
user2:pw2


Done, is it simple?
The reference:
http://trac.lighttpd.net/trac/wiki/Docs%3AModAuth

I got here finally..

There is no a steady spaces that I can note something about development. so I got here, maybe not stable for china can visit some time. but I won't lost my notes any more.