Coolweather_rpc中XMLParser对PHP版本的兼容问题

  从 andot 的网站上找到一个不错的WP插件 coolweather,就是我页面右边那个Weather的东西,利用PHPRpc实现Ajax从 accuweather 的xml接口读取天气信息,经过解析和处理后显示到页面上,是个非常不错的插件。

  在andot写的插件中如果使用到了PHPRpc Server,默认都是在代码里面指向使用他服务器上的PHPRpc Server,这给很多朋友提供了方便,不过也给andot的服务器形成较大压力,导致最近总是服务器无法访问,也就致使andot提供的PHPRpc Server没法连接,也就无法正常返回Weather数据,于是我决定改到使用我自己服务器上的PHPRpc Server,却遇到一点麻烦。

  Coolweather_rpc中用到了xml解析类,这个类据andot说不是他自己写的,从国外下载过来直接使用的,简单的看了一下代码,发现代码并不复杂,但是感觉解析效率并不是很高,简单的xml数据会占用较大的系统开销,不过由于weather数据实在不大,加上访问压力并不大,就先凑合用着吧,等空了改成我原来在3721自己写的一个XML解析类。经过我实际使用,发现这个xml解析类还有个怪现象,那就是在兼容PHP4.x和5.x版本时有问题,最初的现象就是在我的本本上没有问题,上次到toplee服务器上就不能正常解析,让我花了很多时间去定位和排查代码对Windows和FreeBSD的兼容性问题,没想最后发现是因为在toplee服务器上的php.ini中我打开了这样一个选项
[coolcode linenum=”off”]
; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
zend.ze1_compatibility_mode = On
[/coolcode]
  就是这个设置导致了问题,我给改成Off或者把xml_parser.php文件代码改成强制使用xml_parser_php4.php后就没有问题了。

  虽然简单的解决了问题,但是我感觉这个问题应当成为一个普遍的问题提出来考虑,那就是当我们服务器环境要求同时兼容PHP4.x和5.x的时候,代码中应该注意一些什么呢?初步的感觉应该从5.x和4.x的差异入手,有时间专门研究一下,整理一份东西出来今后备用。

Category: PHP / Zend
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
3 Responses
  1. ovidiu says:

    hello,

    can you help me find an english website explaining how I can start using my own rpc server instead of relying on coolcode’s server?

    I remember reading somewhere reading that was possible, but all I can find with google now is chinese or other asian language I don’t udnerstand.

    would be great if you could help

    thx
    ovidiu

  2. Michael says:

    The simplest way is just copy coolcode’s PHPRpc severside’s scripts to your own server, and complish the installtion according to the documentions in the project.

    Another website maybe can give you some help, @see the website for the details: http://www.sitepoint.com/article/own-web-service-php-xml-rpc

  3. ovidiu says:

    thx,

    I discovered the english page on the original plugins page 🙂 which explained this quite a bit.

    thx for the hints

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image