工作很压抑,做没有光明的事情,
自己努力的事情很压抑,忙忙不可见
虽然说¥不应该影响到我的情绪,不过怎么看着、想着别扭别扭闹心。
觉得自己有点像是在兜圈子
ai… i m sick. does sth to cure me….
工作很压抑,做没有光明的事情,
自己努力的事情很压抑,忙忙不可见
虽然说¥不应该影响到我的情绪,不过怎么看着、想着别扭别扭闹心。
觉得自己有点像是在兜圈子
ai… i m sick. does sth to cure me….
什么时候一门语言做坏事了。
不小心上去了一下eclipse的官网,check了一下pdt的版本情况,发现23th june 即将发布 pdt2.2 rc version。
本人期待的功能:
无缝集成explorer文件传输;
消灭文件移动确认(烦人);
文件无确认物理删除(整天搞个svn不放);
build速度;
outline刷新速度;
x.class.php自动类识别;
上面的一个都没有。靠。2.2只是改改code highlight color、code assist 的那堆无痒无痛的。
具体将要update的点可以在这个链接看到:http://www.eclipse.org/pdt/release-notes/pdt2_2.html
看了大牛的一篇文章之后才知道原来include那么的可怕。一个include居然要占用xxms。
还好,偶的东西一开始就在这方面有注意了。
| Function | Time (s) | Memory (b) | ||
|---|---|---|---|---|
| 32Kb File | 1Mb File | 32Kb File | 1Mb File | |
| file_get_contents | 0.00152 | 0.00564 | 52480 | 1067856 |
| fpassthru | 0.00117 | 0.00184 | 20016 | 20032 |
| fgets | 0.00195 | 0.07190 | 30760 | 30768 |
| file | 0.00157 | 0.06464 | 87344 | 2185624 |
| require_once | 0.00225 | 0.08065 | 67992 | 2067696 |
| include | 0.00222 | 0.08202 | 67928 | 2067624 |
| readfile | 0.00117 | 0.00191 | 19192 | 19208 |
在javascript里面,我们可以这样写代码:
var a = function(){ var b = function(){alert('hello');}; b(); }
在PHP里面,我们也可以这么写滴 :D
<?php function a(){ function b(){ echo 'hello'; } b(); } a(); ?>
结果会怎么样呢?是我们预期需要的 hello,但是再来执行一次
a();
a();
程序就会出现function exist 错误了。
原因是:php 函数定义可以放在另一个函数里面,或者对象的方法也可以。当外面的函数被执行的时候,PHP就会将里面的函数提升成为全局函数,因此我们可以在其他的代码里面使用里面的函数b()。但是当外面的函数被多次执行时候,由于php再一次定义里面的函数,因此就会出现function exist错误了。
如果我们还需要这样弄的话,可以加一个 function_exist()来判断之后再去定义,这样就不会出现错误了。
如果一个服务器,你拿不到shell 操作账号,有没有办法实现crontab效果呢?
有!如果服务器对php的函数没有做限制(没有禁用ignore_user_abort函数、set_time_limit函数)就可以实现:
下面这个文件就是实现读取:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | read())){ if($entry != 'crontab.run.php' && filesize($entry) > 0 && array_pop(explode('.', $entry)) == 'php'){ include_once $entry; } } //read crontab list $cron_list = $GLOBALS['PROJECT_CRONTAB_LIST']; if(empty($cron_list)){ exit('NO CRONTAB LIST'); } //init set ignore_user_abort(true); set_time_limit(60); ini_set('time_zone', 'Asia/Shanghai'); $interval = 1; //process while(true){ $c_y = intval(date('Y')); $c_m = intval(date('m')); $c_d = intval(date('d')); $c_h = intval(date('h')); $c_i = intval(date('i')); $c_s = intval(date('s')); foreach($cron_list as $cron){ foreach($cron as $t=>$func){ list($date, $time)= explode(' ', $t); list($y,$m,$d) = array_map('intval',explode('-', $date)); list($h,$i,$s) = array_map('intval',explode(':', $time)); if( ($y == $c_y || $y == 0) && ($m == $c_m || $m == 0) && ($d == $c_d || $d == 0) && ($h == $c_h || $h == 0) && ($i == $c_i || $i == 0) && ($s == $c_s || $s == 0) ){ call_user_func($func); } } } sleep($interval); } ?> |
PHP属于解释性语言,程序员在开发过程中可以很方便的在页面插入debug语句,然后刷新页面进行debug(这一点比java爽多了,java还要恶心的构建)。因此一般php程序员也比较少用到什么其他的debug方法,一般就是echo,die,高深一点的用var_dump来输出变量进行debug。
针对小型的php项目来说,这种debug随手就可以用,确实方便快捷。不过针对稍微大一点的项目,代码量,或者文件多一点的项目,这个就出现问题了(尤其是对一个项目的逻辑不熟悉的时候,例如新人)。众多的die、echo、print_r、var_dump会让自己晕在代码块里面滴 :D
程序员应该善待自己,DEBUG函数必须的要
我们可以使用高深一点的php debug功能debug_backtrace()。相信一般的phper基本上没有怎么接触这类函数。这个函数的功能说白了也就是php内部嵌入的debug 功能变量输出函数。
我们简单的封装一下,构建一个简单的debug函数:
function debug() { $params = func_get_args(); $tmp = $params; //normal debug if(count($params)>0){ $act = array_pop($tmp) === 1; $params = $act ? array_slice($params, 0, -1) : $params; $comma = ''; foreach($params as $var){ echo $comma; var_dump($var); $trace = debug_backtrace(); echo "File: ".$trace[0]['file']." Line : <strong>".$trace[0]['line']."</strong> "; $comma = ' <hr />'; } echo ' '; if ($act){ die(); } } }