php屏蔽出错信息

网站的上线版本应该把php的出错信息屏蔽掉,否则会有些危险。 # 是否是发布版本? $is_release = true; ini_set('display_errors', !$is_release); # 把超时限制改为1s,方便测试执行超时的出错信息 set_time_limit(1); $i = 0; while(++$i){ # 注意sleep的时间,是不包含在max_execute_time里的,所以不用sleep来测试,而只是用个死循环 //sleep(1); }

April 13, 2010 · notsobad

php中的unset

php中unset只是清除掉一个变量,并不意味着内存会被立即清理,会交给GC来处理。 如果把一个变量置为null,意味着覆写了变量,内存会被更快清理,但是会导致cpu运算,导致执行时间变长。 参考 unset() does just what it’s name says - unset a variable. It does not force immediate memory freeing. PHP’s garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren’t needed anyway, or as late as before the script would run out of memory, whatever occurs first. If you are doing $whatever = null; then you are rewriting variable’s data. You might get memory freed / shrunk faster, but it may steal CPU cycles from the code that truly needs them sooner, resulting in a longer overall execution time. ...

December 24, 2009 · notsobad

php的Copy-on-write

参考Be wary of garbage collection 先看段代码: echo "Stage 1: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); for ($i = 0; $i < 1000000; ++$i) { $arr[] = rand(); } echo "Stage 2: Mem usage is: ", memory_get_usage(), "\n"; $foo = 1; $bar = 2; echo "Stage 3: Mem usage is: ", memory_get_usage(), "\n"; $foo = $arr; $bar = $arr; echo "Stage 4: Mem usage is: ", memory_get_usage(), "\n"; $arr = array(); echo "Stage 5: Mem usage is: ", memory_get_usage(), "\n"; $bar[] = "hello, world"; echo "Stage 6: Mem usage is: ", memory_get_usage(), "\n"; $foo = array(); echo "Stage 7: Mem usage is: ", memory_get_usage(), "\n"; 运行结果: Stage 1: Mem usage is: 37712 Stage 2: Mem usage is: 60232136 Stage 3: Mem usage is: 60232248 Stage 4: Mem usage is: 60232248 Stage 5: Mem usage is: 60232288 Stage 6: Mem usage is: 104426704 Stage 7: Mem usage is: 60242672 看stage 4, ...

December 24, 2009 · notsobad

shell中的eval

关于shell中的eval 对于命令注入后,一条命令可能需要的字符大概有这几个吧 $ ' " ; && || [ ] ` > <; 可以看到是很多的,所以黑名单过滤的方法肯定是有问题的,因为是肯可能绕过去的。 加入对所有GET, POST的参数都用了htmlspecialchars做了处理,那么所有的< > 都会被转义成html字符 那么就没办法使用重定向符号了吗? 参考下下面的利用eval来使用管道符号 The shell takes care of pipes and I/O redirection before variable substitution, so it never recognizes the pipe symbol inside pipe. The result is that the three arguments |, wc, and -l are passed to ls as arguments. ...

December 7, 2009 · notsobad

用gnome-web-photo进行网页截屏

参考下这里: http://ubuntuforums.org/showthread.php?t=1085872 还有这里: [http://groups.google.com/group/python- cn/browse_thread/thread/f25350d5e4d415af/08140024364b819d?lnk=gst&q;=html#](http://groups.google.com/group/python- cn/browse_thread/thread/f25350d5e4d415af/08140024364b819d?lnk=gst&q=html#) 使用gnome-web-photo进行网页截屏,效果相当好,不过保存为jpg格式失败了 514 ~/script/sh>gnome-web-photo --format "png" http://blog.notsobad.cn blog.png Registering '@mozilla.org/module-loader/python;1' (libpyloader.so) Registering '@mozilla.org/network/protocol/about;1?what=python' (pyabout.py) 515 ~/script/sh>animate blog.png 516 ~/script/sh>gnome-web-photo --mode=photo --format "jpeg" http://blog.notsobad.cn blog.jpg Registering '@mozilla.org/module-loader/python;1' (libpyloader.so) Registering '@mozilla.org/network/protocol/about;1?what=python' (pyabout.py) JPEG parameter struct mismatch: library thinks size is 372, caller expects 356

August 3, 2009 · notsobad

php模块的调试

python里面有这样的用法 #a.py if __name__ == "__main__": print "test" //只有直接python a.py 才会打印test 意思就是当前脚本独立运行时,才会运行print “test”,这在编写模块,并被其他程序调用时,可以用来调试。 php中没有对应的,今天想起来可以这样做: ...

June 18, 2009 · notsobad

Lisp

最近在用emacs,看了些lisp的东西 原来现代语言的很多特性最早是从lisp中来的 找到几篇很好的文章: 十年学会编程 Lisp之根源 1. 条件语句。当初的语言是没有if else的,goto统治世界。 2. 函数类型。函数成了语言里的类型,可以被变量指代,可以被当成参数传来传去(的一类公民的必要条件,参考SICP第一章)。这一条可以极大简化编程,让我们写出非常漂亮的程序。所以现在的流行语言纷纷加入了这个特性(可惜Java没有)。 3. 递归。这个不用说了吧。 4. 动态类型。smalltalk, python, ruby。。。连C#也有一个类似的var了。 5. 垃圾收集。不要以为GC是Smalltalk的发明哈,更不是Java的。 6. 基于表达式的编程。任何表达式都可以成为另一个表达式的一部分。不像很多语言,把表达和陈述分开。 7. 符号类型。这个在python和ruby里被采用,广受欢迎。 8. 代码即解析树。这个让LISP能方便地定义新的句法,操作程序本身,编写元程序,生成真正意义上的宏。 9. 语言无时不在。代码运行/解析可以在任何时候发生。这点和8.配合可以让语言的扩展和交流变得非常容易。 ...

June 9, 2009 · notsobad

php中的会话阻塞

php中exec, system调用其它脚本,脚本中又将一些脚本放入后台,可能会话会被挂起,也就是其它所有的请求都会被阻塞,点任何链接都没反应。 似乎与这个问题有关: What happens is that the child process which is called by the system() ,exec() or shell_exec() command holds the file lock on the parent process, thus locking the session file. Thus, the session file being locked session_start(); function cannot access the file. This is due to to open file descriptors locking the session file.Your entire session will be locked, so none of the pages of the website can be opened ( which are under session control ) unless you change the browser or delete cookies. ...

June 1, 2009 · notsobad

用umask来定义权限

在linux下,有时需要多人改一个文件, a, b在同一个组内,但是默认的a创建的文件权限是“-rw-r–r–”,组用户是没有写权限的。 我希望修改默认的创建文件的权限,这样不用手动去改,今天发现umask就是干这个事的 这篇讲得很详细 http://linux.vbird.org/linux_basic/0220filemanager.php#umask 所以只要在.bashrc里面写: umask 0002 或者: umask g=rw doubanclaimdcac3ef1e9a427da ...

May 25, 2009 · notsobad

Form中action的参数限制

今天遇到的一个问题及其解决。 这样的一个表单: <form method=post action="/post.php?_in_form=123">... 在server端: <? //取不到$_GET['_in_form']! ?> 查了一些资料 参考: Methods GET and POST in HTML forms - what’s the difference? 关于GET和POST,数据的不同处理 If the method is "get" - -, the user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes. * If the method is "post" --, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype attribute. 结论: get形式的from中,action中的get参数是不会传递的,应该把需要的附加参数作为form隐藏域处理 ...

May 18, 2009 · notsobad