
写个爬虫练练手,php cli 模式下进行的,想实时看看当前爬到那个页面了,爬到第几页了,想到用 file_put_contents 来输出当前的变量值,但是感觉太麻烦,能不能直接查看当前 php 的变量值?
1 zjsxwc 2018-06-01 09:15:42 +08:00 做成交互界面呗,比如用 ncurses http://php.net/manual/en/intro.ncurses.php |
2 OMGZui 2018-06-01 09:25:02 +08:00 只是想看爬到哪个页面和第几页,比如 for 循环,打印出 url 和 i 不就行了。 |
3 zhengwenk 2018-06-01 09:36:21 +08:00 echo $demo."\n" |
4 wangysong 2018-06-01 09:51:21 +08:00 error_log(print_r($data,ture)); 做 php 难道不是用这种方法打印调试日志? 如果不是你需要加载一个三方的 log 库了。。 在不影响程序运行的前提下 监控输出结果。。 如果还不满意 想 debug。 xdebug 了解一下? |
5 MeteorCat 2018-06-01 10:04:16 +08:00 <pre> function watch_info(&$info,$ext_txt = "",$filename = null){ $cOntent="Time:".date("H:i:s"); $content .= "|type:".gettype($info); $content .="|data:`"; if(is_array($info)){ $content .= json_encode($info); }else if(is_null($info)) $content .= "null"; else{ $content .= $info.""; }; $content .="`"; $content .= PHP_EOL; return file_put_contents( $filename ? $filename.date("Y_m_d").".log" : "debug_".date("Y_m_d").".log", $content, FILE_APPEND ); } $info = "test"; $info = array("test"); watch_info($info); </pre> 这种打印到文件之后,直接`tailf debug_xx_xx_xx.log`打印就 OK 了 `tailf`配合文件监控堪称利器 |
6 ioth 2018-06-01 10:05:36 +08:00 换 py |
7 gouchaoer2 2018-06-01 11:05:24 +08:00 用 xdebug+phpstorm 可以做到单步调试的,我就是这么做的 |
8 dobelee 2018-06-01 11:14:29 +08:00 via Android 封一打印方法就 ok。 |
9 RorschachZZZ 2018-06-01 11:27:26 +08:00 直接 echo,记住要换行 echo $msg, PHP_EOL; |
10 update 2018-06-01 11:58:25 +08:00 用 5 楼的方法或者封装个 echo 都可以实现 |
11 GoPHP 2018-06-01 12:04:15 +08:00 用 xdebug+phpstorm 可以做到单步调试的,我就是这么做的 +1 |