[原创]由Web Service展开的联想… …

June 17, 2008 – 3:41 am
    最近互联网流行web service,这个东西像广告一样铺天盖地砸到我们头上,就这样,一群茫然的程序员开始了web service之旅... ...     拜读了OReilly和Apress的大作(基本看完了主要内容),紧跟着又实验了yahoo!和google的搜索web service,忽然有种感觉,web service很类似Ajax,都是有点新瓶装旧酒的味道。     什么是web service呢?让我们不用计算机的术语来解释,几个工厂生产奇形怪状的管子,有的是漏斗形状的(yahoo.com),有的是超级粗的(google.com),有的是超级细的(amazon.com),但是唯一统一的是生产出来的管子的两端,就是两端的接口口径都是统一的(XML语言),所有这些奇形怪状的管子都可以严丝合缝的组合在一起,水(数据)就可以在里面通畅得流动,如果哪家工厂的管子两端接口的口径不按照标准统一生产,那就会有两种结果,一种是水漏得厉害(数据无法正常传送),一种是谁的管子都不和它连接(孤立的网站,估计结果是关门)。这就是我理解的web service。     那么为什么说web service类似Ajax,都有点新瓶装旧酒的意思呢?我认为,这种统一标准,便于网站数据流通的方法实际上已经被许多网站开发人员在不知不觉中使用了。尤其对于使用不同开发语言的项目来说,一个PHP程序模块和另一个JAVA程序模块保持通讯,在项目内部或者互相提供一个ID(接受的程序自己去查询),或者提供一个数组,当然也会有人使用XML标记语言。呵呵,现在web service被提出来了,等于给这些程序员出于本能使用的技术赋予了一个名字,那就是——Web Service。同样的道理,对外提供接口让用户基于你的网站开发小程序也是这个道理。大家的程序语言不必统一,只要互相能提供相同的XML文件即可。     今天看得有点多,写下一点感想,不对的地方敬请赐教,谢谢!

[Original]An Identifying Code Pic Class using PHP GD Lib.

May 14, 2008 – 7:04 pm
Yesterday I took one hour to study PHP GD lib.I read this book's chapter which is about PHP Advanced Pic Technology.The picture which can descripe this book is below. After reading it,I felt it is easy to operate pic using PHP GD.When I home,I suddenly wanted to write a PHP Class which includes Identifying Code Pic's function.Now I published this class.Thank you for pointing out my issue and leaving your comment. /* *@date 20080514 *@author hluan *@package Identifying.Code.Pic.Class *@attention Before using this class,you should use session_start(); */ //session_start(); class icode { function __construct(){ header('Content-Type:image/png'); } function __destruct(){ imagedestroy($png); } /************************************************** *@len The length of the identifying code. *@type 1:only number identifying code; * 2:only letter identifying code; * 0:number and letter identifying code. *@attention We store identifying code in $_SESSION['icode']. **************************************************/ function getcode($len,$type){ switch ($type){ case 1; $str = "1234567890"; break; case 2; $str = "abcdefghijklmnopqrstuvwxyz"; break; case 0; $str = "1234567890abcdefghijklmnopqrstuvwxyz"; break; } $result = ""; $length = strlen($str) - 1; $num = 0; for ($i=0;$i<$len;$i++){ $num = rand(0,$length); $a = $str[$num]; $result = $result.$a; } /*Before using it,you should use session_start()*/ $_SESSION['icode'] = $result;//Store in session. //echo "session:".$_SESSION['icode']; //die(); $png = imagecreate(60,30); $white = imagecolorallocate($png,255,255,255);//background $red = imagecolorallocate($png,255,0,0); $blue ...

[原创]PHP GD图片验证码类。

May 14, 2008 – 6:30 pm
昨天拿一个小时研究了一下PHP GD类库的使用方法,实际就是看了这本书 中的PHP图像技术一章节,感觉PHP利用GD类库操作图片的确很方便。晚上回家忽然萌生了写一个PHP图片验证码类的想法。所以就有了下面的代码,呵呵,现在贴出来,请大家多提宝贵意见,谢谢! ****************************** *@date 20080514 *@author hluan *@package Identifying.Code.Pic.Class *@attention Before using this class,you should use session_start(); ******************************/ //session_start(); class icode { function __construct(){ header('Content-Type:image/png'); } function __destruct(){ imagedestroy($png); } /************************************************** *@len The length of the identifying code. *@type 1:only number identifying code; * 2:only letter identifying code; * 0:number and letter identifying code. *@attention We store identifying code in $_SESSION['icode']. **************************************************/ function getcode($len,$type){ switch ($type){ case 1; $str = "1234567890"; break; case 2; $str = "abcdefghijklmnopqrstuvwxyz"; break; case 0; $str = "1234567890abcdefghijklmnopqrstuvwxyz"; break; } $result = ""; $length = strlen($str) - 1; $num = 0; for ($i=0;$i<$len;$i++){ $num = rand(0,$length); $a = $str[$num]; $result = $result.$a; } /*Before using it,you should use session_start()*/ $_SESSION['icode'] = $result;//Store in session. //echo "session:".$_SESSION['icode']; //die(); $png = imagecreate(60,30); $white = imagecolorallocate($png,255,255,255);//background $red = imagecolorallocate($png,255,0,0); $blue = imagecolorallocate($png,0,0,255); $brown = imagecolorallocate($png,100,0,0); $black = imagecolorallocate($png,0,0,0);//Identifying Code imagefill($png,0,0,$white); $k = rand(0,3); if (0 == $k){ for ($n=0;$n<60;$n++){ $y = 15*sin($n/30*pi()); imagesetpixel($png,$n,15+$y,$red); } }else if (1 == $k){ for ($n=0;$n<60;$n++){ $y = 15*cos($n/60*pi()); imagesetpixel($png,$n,15+$y,$red); } }else if (2 == $k){ for ($n=0;$n<60;$n++){ $y = 15*sin($n/45*pi()); imagesetpixel($png,$n,15+$y,$brown); } }else if (3 == $k){ for ($n=0;$n<60;$n++){ $y = 15*cos($n/30*pi()); imagesetpixel($png,$n,15+$y,$brown); } } for ($k=0;$k<10;$k++){ $i = rand(3,60);//width $j = rand(3,15);//height imageline($png,$i-3,$j-3,$i,$j,$black); } imagestring($png,5,3,5,$result,$blue); $icode = imagepng($png); return $icode; } } /*测试getcode代码 $icode = new icode(); $icp = $icode->getcode(6,0); echo $icp; */

[原创中文翻译]symfony askeet24:终于校译完了… …

March 20, 2008 – 11:24 pm
    今天终于完成了校译,我已经连续很长时间没有好好享受一下业余休息时间了... ...呵呵!虽然比较劳累,但是心里很高兴,毕竟这件事情有始有终得完成了。Never do another thing when you have not finished one yet. 想想2007年10月份,当时我心里都琢磨我能不能把这24篇英文文章翻译完,而且对于一个还没有把PHP完全掌握好的新手来说,翻译一份PHP开发框架的实践使用教材,而且要弄懂框架里的东西,压力似乎比较大。 就好比你还没有完全学会爬,就开始进行跑的动作。天啊!我都挺佩服我当时的想法。不过,人能成功都是被逼出来的,天下事没有什么怕的,只要你具备有毅力,没有你做不好的!艰难的翻译开始了,中间夹杂着重新温习PHP基本嵌套开发,体会PHP MVC模式开发思想,甚至我自己写了一个小的MVC框架的PHP论坛来拼命练习,光这些当然是不够的,还要熟读Symfony文档,尤其是大量的API文档。呵呵!个中的滋味只有自己知道。 校译完成了,下面还有很多需要做的... ...

[原创]symfony中module的命名问题。

March 13, 2008 – 9:17 pm
最近一直在试验symfony,今天偶然发现了module命名的一个小问题。写下来大家一起讨论一下。 做法:新建项目,建立myapp,然后创建moduel,名字取default,这个时候访问项目url(最好使用开发模式url),显示见下图: 这个时候在module default的action里actions.class.php文件里加一个方法,例如list,list的功能随便你定义,可以从数据库里随便取几个数据,当然了,要创建对应的listSuccess.php模板来显示对应动作传的数据;然后修改默认方法index的$this->forward('default',module);为$this->forward('default','list');。这一切都做完后,修改myproject/apps/myapps/config/routing.yml路由协议文件中的homepage部分为param: { module: default, action: list}。当这一切都做好后,运行symfony cc清除所有缓存。 现在访问项目url,展现在你眼前的页面只是default module的动作actions.class.php中list方法对应的listSuccess.php模板内容,没有layout.php的内容。 如果你是用除default以外的名字命名module,目前为止还没出现过上面的情况。此类问题在学习官方手册时也没见有提醒命名规则的内容。个人感觉symfony的内部处理机制在转到layout.php布局时存在一个默认的module和控制动作,名字应该就是default。 以上只是个人的理解,如果有不同意见,请留言。

[原创中文翻译]symfony askeet24:第二十四天,后面的工作是什么呢?

October 11, 2007 – 2:35 am
[欢迎转载,转载请注名出处http://symfony.net.cn。本文英文版权归symfony官方网站所有] (译者:这是最后一篇了,大体是关于akseet程序的用途,安装,下载,文档等一系列内容,随意看看就行,笔者只翻译了文件结构和数据模型等部分。) Use it 使用askeet The askeet website is open to the public. You can advertise it and talk about it to your friends and relatives. Some of the test contributions will be removed, but most of the existing questions and user accounts will remain. Askeet is a great tool to find answers - provided that many users visit it. So spread the word. askeet对公众开放。你可以为它作宣传或者向你的亲朋好友介绍它。测试的数据都被删除了,但是大部分问题和读者账号都会保留。askeet是你寻找答案的好工具。上面的答案来自全世界的热心者。 Opening an account is fast and easy, and requires nothing but a nickname, a password, and an email. It allows you to declare interest about questions, to ask new questions, and to rate answers. The email address will not be used for any kind of advertising, ever. 申请开通一个读者帐号又快又容易,不需要别的资料,只需要一个用户名,一个密码,一个电子邮件地址即可。你可以对某问题表示“感兴趣”,发布新问题,“顶”或“踩”答案。并且您的电子邮件地址不会用来做广告。 Subscribe to the RSS feeds to keep informed about the latest questions, or about the answers to the questions you asked. Askeet can also be a way to make some money, since user profiles can be linked to a Paypal account. If a user finds your ...

[原创中文翻译]symfony askeet24:第二十三天,网站国际化。

October 11, 2007 – 2:07 am
[欢迎转载,转载请注名出处http://symfony.net.cn。本文英文版权归symfony官方网站所有] Localization 本地化 What if the call to an address like: 这个URL如何: http://fr.askeet.com/ ...displayed only the French questions? Well, this is quite easy, because since the eighteenth day, such an URI is understood as a universe. ... ...只显示法语问题。很简单,第八天的教材URL可以被当作标签处理。 Content 内容 Creating a question in a language universe will have it tagged automatically with the language tag (here: 'fr'). And, if you browse the 'fr' universe, only the questions with the 'fr' tag will appear. 在对应预言二级域名下创建的问题会自动按照语言标签被加上标签(这里是fr)。如果你访问带fr的二级域名,只有带fr标签的问题会显示。 So the universe filter already takes care of content localization. That was an easy move. 那么过滤器该关心本地化内容了。这是个很简单的修改。 Look and feel 感官感受 The universes can have their own stylesheet. This means that the look and feel of a localized askeet can be easily adapted as well, with the same mechanism. Next, please. 二级域名下的页面可以有他们自己的样式。这意味着本地化askeet的不同界面显示可以很简单,用同样的原理实现。下面,请吧。 Language-dependent functions 语言-支持功能 The database indexing system built during the twenty-first day relies on a stemming algorithm which is language-dependant. In a localized version, it has to be adapted. 第二十一天数据库索引系统建立,靠的是stemming算法,其中就是种语言-支持。在本地版本里,这需要被改写。 For now, there is no available stemming library for other languages than English in PHP, but ...

[原创中文翻译]symfony askeet24:第二十二天,上传服务器发布网站。

October 11, 2007 – 1:01 am
[欢迎转载,转载请注名出处http://symfony.net.cn。本文英文版权归symfony官方网站所有] Synchronization 同步 Good practices 推荐的方案 There are a lot of ways to synchronize two environments for a website. The basic file transfers can be achieved by an FTP connection, but there are two major drawbacks to this solution. First, it is not secure, the data stream transmits in the clear over the Internet and can be intercepted. Second, sending the root project directory by FTP is fine for the first transfer, but when you have to upload an update of your application, where only a few files changed, this is not a good and fast way to do it. Either you transfer the whole project again which, can be long or you browse to the directories where you know that some files changed, and transfer only the ones with different modification dates. That's a long job, and it is prone to error. In addition, the website can be unavailable or buggy during the time ...

[原创中文翻译]symfony askeet24:第二十一天,创建搜索引擎。

October 10, 2007 – 7:53 pm
[欢迎转载,转载请注名出处http://symfony.net.cn。本文英文版权归symfony官方网站所有] How to build a search engine? 怎么创建一个搜索引擎呢? The most popular suggestion about the 21st day addition proved to be a search engine. 第二十一世纪最流行的是互联网搜索引擎。 If the Zsearch extension (a PHP implementation of the Lucene search engine from Apache) had already been released by Zend, this would have been a piece of cake to implement. Unfortunately, Zend seems to take longer than expected to launch their PHP framework, so we need to find another solution. 如果Zend已经发布了Zsearch搜索引擎(apache下用PHP实现的一个搜索引擎),用PHP构建搜索引擎的蛋糕就等于少了一片。遗憾的是(我看作者是暗自高兴),Zend似乎还要花很长时间来研究他的PHP框架,所以我们使用其他方法来构建我们的搜索引擎。 Integrating a foreign library (like, for instance, mnoGoSearch) would probably take more than one hour, and lots of custom adaptations would be necessary to obtain a good result for the askeet specific content. Plus, foreign search libraries are often platform or database dependant, and not all of them are open-source, and that's something we don't want for askeet. 使用外部的类库(例如,mnoGoSearch)开发需要花费超过一小时时间,许多的自定义修改会变得很有必要,因为askeet的内容特别而且多。另外,外部search类库通常需要数据库和平台支持,他们并不全是开源免费的,这可不是我们的askeet开发想要的。 The MySQL database offers a full-text indexation and search for text content, but it is restricted to MyISAM tables. Once again, basing our search engine ...

[原创中文翻译]symfony askeet24:第二十天,增加管理员和版主。

October 10, 2007 – 2:23 am
[欢迎转载,转载请注名出处http://symfony.net.cn。本文英文版权归symfony官方网站所有] The expected result: what the client says 需求分析:客户的要求是什么 Today's job will consist of a few new actions, new templates and new model method, and we already know how to do that. The hardest part is probably to define what is needed, and where to put it. It is both a functional and usability concern, and it's a good thing that developers focus on something else than code every once in a while. 今天的工作包含创建一些新动作、新模板和新模型方法,我们都知道该怎么做了。设计中最难的部分是定义项目怎么做,在那里需要实现某些功能,在那里不需要实现某些功能。方法和可用的组件、开发者的代码都必须结合起来。 (译者:这里确实该好好看看,项目的前期定义是非常重要的。这里一点一点讲解了askeet后台的定义内容,看起来一目了然。弄明白了再去开发程 序,绝对不会出现功能上的遗漏和错误。可惜的是,现阶段中国的软件科技公司很少有做得比较好的,是这个东西不重要么?不是,要不然为什么国内、国外只要涉 及软件的书都写这个重要呢;是项目时间紧张么?不是,没有好的设计,甚至没有文档,造成的项目拖延时间是几何级数的;是中国的程序员笨蛋么?更不是,大家的脑子都很聪明!那是 什么呢?我想说的是第一,懒惰;第二,自以为是;第三,意识上还不到真正软件工程师的程度。) It will be the opportunity to illustrate one of the tasks of the eXtreme Programming (XP) methodology: the writing of stories, and the work that developers have to do to transform stories into functionality. XP is one of the best agile development approaches, and is usually applicable to web 2.0 projects like askeet. 这是个解释极限编程的好例子:stories,开发者需要干的是实现stories为具体功能。入门敏捷开发最好方式之一就是写程序,尤其是类似askeet这样的web 2.0项目。 Stories Stories In XP, a story is a brief description of the way an action of the user triggers a reaction of the application. Stories are written ...