Apr 07, 2008
像Discuz!,phpwind等论坛页面下方都有统计页面SQL查询次数的功能,这个blog数据库访问层使用的是
adodb,让我们来为它添加一个相应的统计功能。(现在
首页上的统计功能就是用这个实现的)
adodb以OOP思想来写的,都已经封装好了,所以修改起来比较简单。
所有的查询方法(比如Execute,GetOne,GetRow等)最终都是调用特定数据库实现类的_query方法执行的。
在这个地方动下手脚就可以实现这个功能了。
设一变量,初始化为0,每次调用便加1。以mysql实现adodb-mysql.inc.php为例
-
-
-
-
-
- class ADODB_mysql extends ADOConnection {
-
- var $queryTimes = 0;
-
-
- function _query($sql, $inputarr) {
-
- $this->queryTimes++;
-
-
- }
-
-
- function getQueryTimes() {
- return $this->queryTimes++;
- }
- }
Feb 12, 2008
如果您觉得PHP能像JAVA、Visual Studio等IDE一样进行代码调试很重要,就继续往下看。
半年前的“eclipse+pdt+xdebug PHP集成开发环境”是上次重装系统时,方便自己下次重装系统时快速搭建PHP集成开发环境时记录的。
现在看来,似乎没起到一点方便的作用。反而成了目前日志中浏览量最高的一篇日志了,但内容却极其简单。
现在又准备重装系统了,再为了方便下次重装,详细的记录一下。
在上一篇文章中PDT有一点小问题,在调试时显示Variables时有问题。
现在PDT1.0.2已经Release了,刚简单的试了下,上述问题已经修正,语法提示功能也有增强。
为了方便重装系统时尽量做最小的改动,选择了XAMPP解压缩版(重装后,只需运行一次setup_xampp.bat即可),现在最新版是1.6.6
下面记下安装及设置调试过程:
软件:
- XAMPP 1.6.6 解压缩版,下载地址:点击这里
- PDT 1.0.2 Release All-in-One,下载地址:点击这里
- XDebug 2.0.2 | Windows modules PHP 5.2.1-5.2.7,下载地址:点击这里
注意xdebug的版本必须和XAMPP中的PHP版本兼容,XAMPP 1.6.6中PHP版本是5.2.5,所以使用XDebug 2.0.2 | Windows modules PHP 5.2.1-5.2.7
安装:
阅读全文 "Eclipse/PDT xdebug 调试PHP" »
Aug 20, 2007
上一篇日志中有点小错误,以为del.icio.us是通过BloggerAPI来发送最新的网页收藏,经过测试其实是用MetaWeblog API来实现的。
现在很多本地博客客户端程序远程提交日志一般都是用BloggerAPI, MetaWeblog API来实现的,只不过他们实现了整个相关接口。我们来实现一个最简单的接收功能。:)
相关资源
XML-RPC for PHP: http://phpxmlrpc.sourceforge.net
MetaWeblog API: http://www.xmlrpc.com/metaWeblogApi
RSS2.0: http://blogs.law.harvard.edu/tech/rss
先用xml-rpc for php实现一个xml-rpc服务端:
-
-
-
-
- $s = new xmlrpc_server(array(
- 'metaWeblog.newPost' => array(
- 'function' => 'newPost'
-
-
-
- )
- ));
-
-
- function newPost($m) {
- global $xmlrpcerruser;
-
- $n = php_xmlrpc_decode($m);
-
- $blogid = $n[0];
- $username = $n[1];
- $password = $n[2];
- $struct = $n[3];
- $publish = $n[4];
-
- $title = $struct['title'];
- $content = $struct['description'];
-
-
-
-
-
- if ($failure) {
-
- return new xmlrpcresp(0, $xmlrpcerruser, "failure");
- } else {
-
- return new xmlrpcresp(new xmlrpcval("$uuid", "string"));
- }
- }
然后进入del.icio.us -> settings -> daily blog posting -> add a new thingy 中设置xml-rpc服务端地址、用户名、密码等。
上述代码就可以完成接收del.icio.us最新收藏的功能。应该再过几十分钟del.icio.us就会发送一篇收藏到这个日志中来。
如果没有,就是我人品有问题了。
Jun 26, 2007
最后更新: 2008-02-12 此日志有更新版本:http://www.ajaxeye.com/blog/54/
其实zend studio上面的功能都有,debug功能又很方便。
但是有时写写js或xml等,那些代码提示什么的都没了。而eclipse下插件几乎涵盖了各方面,php可以用pdt、js可以用aptana、xml可以用xmlbuddy等等。
eclipse+pdt安装很简单,官网上有all-in-one下载,但要加上debug功能就比较反繁琐。照着参照步骤一步一来还是没有问题的。
安装的时候一定要注意版本对应的问题,偶装的是apache2.2.4, php5.2.1, php_xdebug.dll(for php5.2.1)
apache安装
直接下一步,下一步就OK,测试时看到It works!说明安装成功
php安装
参考http://www.php.net/manual/zh/install.windows.apache2.php
安装好后写个phpinfo文件测试下
eclipse+pdt安装(需先安装jre)
http://download.eclipse.org/tools/pdt/downloads
下载S20070401-RC3 all-in-one
最新的S20070611-M1 all-in-one最终安装好后,调试时显示Variables时有问题
xdebug安装
https://bugs.eclipse.org/bugs/show_bug.cgi?id=169408
下载Prebuilt Binary of XDebug Support V0.2.2 for PDT RC3 only
在上面这个附件中有pdt xdebug插件及XDebugGuide.pdf
参照XDebugGuide.pdf中内容安装(精华就在这里) :)
安装详细步骤没有写下来,上面的链接中文章都说的非常清楚了
有什么问题留言,呵呵
Apr 02, 2007
(一)中讲到了wordpress是如何读取系统中所有插件的。
现在我们来看看她是如何激活及停用插件的。
激活及停用插件
wordpress的当前使用的插件列表存放在数据库中,wp_options表,字段option_name值为active_plugins的列存放的就是当前系统中使用的插件。
a:2:{i:0;s:9:"hello.php";i:1;s:16:"wp-db-backup.php";}
就是当前系统中使用的两个插件Hello Dolly、WordPress Database Backup。
这个字段原有类型是array,经过serialize后存放在数据库中,读出时unserialize。
取得当前系统中使用的插件 functions.php | 273行 | function get_settings($setting) {}
-
-
- $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
-
-
-
- if( is_object( $row) ) {
- $value = $row->option_value;
-
- wp_cache_set($setting, $value, 'options');
- }
-
-
- return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
-
-
-
-
-
-
-
-
-
-
-
-
激活插件
通过链接plugins.php?action=activate&plugin=hello.php
wp-admin/plugins.php | 5行左右 |
-
- $current = get_settings('active_plugins');
-
- if (!in_array($_GET['plugin'], $current)) {
-
- $current[] = trim( $_GET['plugin'] );
- sort($current);
-
-
- update_option('active_plugins', $current);
-
-
- }
停用插件
通过链接plugins.php?action=deactivate&plugin=hello.php
wp-admin/plugins.php | 16行左右 |
-
- $current = get_settings('active_plugins');
-
- array_splice($current, array_search( $_GET['plugin'], $current), 1 );
-
-
- update_option('active_plugins', $current);
-
-
Mar 30, 2007
wordpress目前非常流行一款开放源代码基于php,mysql的blog系统,尤其是她的插件机制更让人着迷。有很多wordpress插件的相关网站。
让我们来一起剖析她的插件机制的实现吧。
wordpress是怎么读取当前所有插件的?
wordpress的插件存放在wp-content\plugins目录下,可以直接存放在plugins或plugins的二级目录下。
登录后台进入Plugins栏目可以查看当前所有存在的插件相关信息。
以Hello Dolly插件为例。
wp的插件相关描述存放在php文件内容开始的地方
读取当前系统中插件文件夹中的文件 admin-functions.php | 1516行 | function get_plugins() {}
-
-
- $plugins_dir = @ dir($plugin_root);
- if ($plugins_dir) {
- while (($file = $plugins_dir->read()) !== false) {
-
- if (preg_match('|^\.+$|', $file))
- continue;
-
- if (is_dir($plugin_root.'/'.$file)) {
- $plugins_subdir = @ dir($plugin_root.'/'.$file);
- if ($plugins_subdir) {
- while (($subfile = $plugins_subdir->read()) !== false) {
-
- if (preg_match('|^\.+$|', $subfile))
- continue;
-
- if (preg_match('|\.php$|', $subfile))
- $plugin_files[] = "$file/$subfile";
- }
- }
- } else {
-
- if (preg_match('|\.php$|', $file))
- $plugin_files[] = $file;
- }
- }
- }
-
- foreach ($plugin_files as $plugin_file) {
- if ( !is_readable("$plugin_root/$plugin_file"))
- continue;
-
-
- $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
-
- if (emptyempty ($plugin_data['Name'])) {
- continue;
- }
-
- $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
- }
-
-
-
-
- return $wp_plugins;
分析每个插件的相关描述信息 admin-functions.php | 1486行 | function get_plugin_data($plugin_file) {}
-
- $plugin_data = implode('', file($plugin_file));
-
- preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
- preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
- preg_match("|Description:(.*)|i", $plugin_data, $description);
- preg_match("|Author:(.*)|i", $plugin_data, $author_name);
- preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
- if (preg_match("|Version:(.*)|i", $plugin_data, $version))
- $version = trim($version[1]);
- else
- $version = '';
-
-
-
- return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
wp-admin/plugins.php 调用 get_plugins() {} 方法显示所有插件,读取完毕。