Press "Enter" to skip to content

PHP CLI模式下的多进程应用

PHP在很多时候不适合做常驻的SHELl进程, 他没有专门的gc例程, 也没有有效的内存管理途径. 所以如果用PHP做常驻SHELL, 你会经常被内存耗尽导致abort而unhappy.
而且, 如果输入数据非法, 而SHELL没有检测, 导致abort, 也会让你很不开心.
那? 怎么办呢?
多进程....

Filed in PHP应用
with 38 Comments

PHP+Gtk实例(求24点)

最近要安排我为BIT提供的《PHP高级应用--关于PHP你不知道的》一门课的讲课素材, 其中有部分涉及到PHP和Gtk2开发桌面应用的部分, 于是抽空就想写一了一个demo出来.
这是一个经典的求24的算法的PHP实现, 加上了Gtk2的界面, 其实也没什么复杂的, 和MFC开发没什么太大的区别, 唯一的不爽, 就是要自己用代码来写布局。。。
有兴趣的同学可以看看.

Filed in PHP应用
with 17 Comments

数组非数字键名引号的必要性

我看到过很多人操作数组的时候, 对于数组中的非数字键名不使用引号,

  $array[key] = $value;

我可以理解有些人可能会觉得这样的代码很"整洁", 并且也能正常执行.
更甚至,如果他很"幸运的"php配置的好:

error_reporting = ~E_NOTICE

他也许永远都沉浸在自己的"整洁"风格中, 看不到任何的NOTICE提示, 也不会意识到, 他这么做, 能损失多少的性能~
来, 我们一起来看看:

Filed in PHP应用, PHP源码分析
with 27 Comments

PHP字符串比较

我们在代码中用的最多的逻辑是什么?
你知道如下的几段代码的布尔结果分别是什么么?
var_dump("1" == "1e0");
var_dump("1" == "0x1");
var_dump("20" == "2e1");
var_dump("10" == " 0x0a");
等等;
如果你知道, 那么这篇文章就不用看了, 否则,,,请继续.

Filed in PHP应用
with 11 Comments

Mess it up!

恩,这段代码还能再乱点,再让人无语点么?

<?php
/*  @author: laruence<laruence.yahoo.com.cn>  */
$___="000010000009000009000074000117000115000116000032000079000110000101000032000076000097000115000116000032000068000097000110000099000101000032000010000074000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000046000046000046000046000111000104000032000098000097000098000121000046000046000046000106000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000032000010000010000087000101000032000109000101000101000116000032000105000110000032000116000104000101000032000110000105000103000104000116000032000105000110000032000116000104000101000032000083000112000097000110000105000115000104000032000099000097000102000195000169000032000010000073000032000108000111000111000107000032000105000110000032000121000111000117000114000032000101000121000101000115000032000106000117000115000116000032000100000111000110000039000039000116000032000107000110000111000119000032000119000104000097000116000032000116000111000032000115000097000121000032000010000073000116000032000102000101000101000108000115000032000108000105000107000101000032000073000039000039000109000032000100000114000111000119000110000105000110000103000032000105000110000032000115000097000108000116000121000032000119000097000116000101000114000032000010000065000032000102000101000119000032000104000111000117000114000115000032000108000101000102000116000032000116000105000108000108000032000116000104000101000032000115000117000110000039000039000115000032000103000111000110000110000097000032000114000105000115000101000032000010000116000111000109000111000114000114000111000119000032000119000105000108000108000032000099000111000109000101000032000097000110000032000105000116000039000039000115000032000116000105000109000101000032000116000111000032000114000101000097000108000105000122000101000032000010000111000117000114000032000108000111000118000101000032000104000097000115000032000102000105000110000105000115000104000101000100000032000102000111000114000101000118000101000114000032000010000010000104000111000119000032000073000032000119000105000115000104000032000116000111000032000099000111000109000101000032000119000105000116000104000032000121000111000117000032000040000119000105000115000104000032000116000111000032000099000111000109000101000032000119000105000116000104000032000121000111000117000041000032000010000104000111000119000032000073000032000119000105000115000104000032000119000101000032000109000097000107000101000032000105000116000032000116000104000114000111000117000103000104000032000010000010000074000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000032000010000098000101000102000111000114000101000032000119000101000032000115000097000121000032000103000111000111000100000098000121000101000032000010000119000104000101000110000032000119000101000032000115000119000097000121000032000097000110000100000032000116000117000114000110000032000114000111000117000110000100000032000097000110000100000032000114000111000117000110000100000032000097000110000100000032000114000111000117000110000100000032000010000105000116000039000039000115000032000108000105000107000101000032000116000104000101000032000102000105000114000115000116000032000116000105000109000101000032000010000074000117000115000116000032000111000110000101000032000109000111000114000101000032000099000104000097000110000099000101000032000010000104000111000108000100000032000109000101000032000116000105000103000104000116000032000097000110000100000032000107000101000101000112000032000109000101000032000119000097000114000109000032000010000099000097000117000115000101000032000116000104000101000032000110000105000103000104000116000032000105000115000032000103000101000116000116000105000110000103000032000099000111000108000100000032000010000097000110000100000032000073000032000100000111000110000039000039000116000032000107000110000111000119000032000119000104000101000114000101000032000073000032000098000101000108000111000110000103000032000010000074000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000032000010000010000084000104000101000032000119000105000110000101000032000097000110000100000032000116000104000101000032000108000105000103000104000116000115000032000097000110000100000032000116000104000101000032000083000112000097000110000105000115000104000032000103000117000105000116000097000114000032000010000073000039000039000108000108000032000110000101000118000101000114000032000102000111000114000103000101000116000032000104000111000119000032000114000111000109000097000110000116000105000099000032000116000104000101000121000032000097000114000101000032000010000098000117000116000032000073000032000107000110000111000119000044000032000116000111000109000111000114000114000111000119000032000073000039000039000108000108000032000108000111000115000101000032000116000104000101000032000111000110000101000032000073000032000108000111000118000101000032000010000084000104000101000114000101000039000039000115000032000110000111000032000119000097000121000032000116000111000032000099000111000109000101000032000119000105000116000104000032000121000111000117000032000010000105000116000039000039000115000032000116000104000101000032000111000110000108000121000032000119000097000121000032000116000111000032000100000111000032000010000010000074000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000044000032000106000117000115000116000032000111000110000101000032000109000111000114000101000032000099000104000097000110000099000101000044000032000106000117000115000116000032000111000110000101000032000108000097000115000116000032000100000097000110000099000101000010000010000009000009000009000009000009000009000009000009000045000045000045000084000104000105000115000032000083000099000114000105000112000116000032000105000115000032000106000117000115000116000032000102000111000114000032000073000079000080000067000067000032000010000009000009000009000009000009000009000009000009000009000009000009000108000097000114000117000101000110000099000101000032000050000048000048000057000046000048000049000046000048000055"; $_______="\x70\x61\x63\x6b";$________=$_______("\x63\x36",115,116,114,108,101,110);$_=$________($________);$__________=$_______("\x63\x36",115,117,98,115,116,114);$_________=$_______("\x63\x36",105,110,116,118,97,108);$________($________);$__=$_______("\x63\x36",111,114,100,99,104,114);$___________=$_______("\x63\x35",119,104,105,108,101);while($____=$__________($___,$_______=$_________($_______),$_)){$_____=$__________($__,3,3);echo$_____($_________($____));while($_--){$_______++;}$_=$________($________);}?>

想知道这段代码干了什么么?

Filed in PHP应用
with 22 Comments

一个低概率的PHP Core dump

PHP是个脚本语言, 错误定位容易, 编写起来速度较快..但是, 如果遇到了PHP自身的一些问题,那就会让人很恼火.
最近遇到一个很低概率的Core dump(大概是2年才出现一次), 经过和同事一起仔细分析,跟踪,终于找出了原因, 拿出来与大家分享.

Filed in PHP应用, PHP源码分析
Comments closed

深入理解PHP原理之foreach

foreach是PHP中很常用的一个用作数组循环的控制语句。
因为它的方便和易用,自然也就在后端隐藏着很复杂的具体实现方式:(对用户透明)
今天,我们就来一起分析分析,foreach是如何实现数组(对象)的遍历的。
本节内容涉及到较多编译原理(lex and yacc)的知识,所以如果您觉得看不太懂,可以先找相关的资料看看。

Filed in PHP应用, PHP源码分析
with 21 Comments