最近為了在網頁中使用一個 C Library,從頭寫了一個 PHP PECL Extension。期間自然做了一些調查與研究,在此寫下供其他朋友作為參考。

首先應瞭解開發 PECL 時,一些必要得知識,像是基本的 Zend SAPI、每個模組的生命週期、記憶體管理、ZVAL 參數的取得等等。關於這方面的知識,除了已經相對太舊的Zend API – Hacking the Core of PHP 外,Sara Golemon 算是著述的較多的開發者,他甚至出了一本書叫做《Extending and Embedding PHP》,去年在 ZendCon 2008 也談過一次 PHP Extension Writing

不過要完成一個 PECL Extension,大約不需要讀完一本書,Sara Golemon 在 2005 年時亦在 Zend Developer Zone 發表幾篇詳盡的技術文章,說明了最重要的幾個重點,讀過跟著做一次,大約就可以熟悉一些基本的技巧。我並沒有發現 Zend SAPI 的詳細文件,因此必須再翻翻 /usr/include/php5/Zend 下的 header files,看看其他 core extensions 的程式碼,大概就可以掌握完成一個 Extension 的知識。

Sara Golemon 的幾篇經典文章是

英文若嚥不下,或可參考 Huang Shiqiang簡體中文翻譯。Huang Shiqiang 尚做了一個以 C 為基礎的 PHP Framekwork – Kiss (計畫網頁),頗有趣。以效能為出發點的 framework 或 template engine 還有 Blitz 等。

讀過文章,瞭解基本的概念之後,就可以開始動手寫程式。首先,你得有開發環境,包含編譯檔案、目錄結構、文件封裝機制等。你自然可以動手複製一份別人的來改,或者你可以依照 PHP Manual 中的說明利用 ext_skel 來產出一個空白的專案。我自己是利用功能相較完整一點的 CodeGen_PECL。利用 Pear 裝好後,就可以利用 pecl-gen 生出一份空白的專案。

PHP Extension 預設利用 phpize 來自動生成 autotools scripts,對開發者來講,若要新增編譯參數或增加原始檔案,只需要增修 config.m4 中的內容即可,不用管整套的 autotools scripts,算是相當方便。config.m4 是用 m4 這個 macro processor 來處理,語法這裡就略過不提了,編譯文件應相當好找。

撰寫一個 Extenstion 的知識大概是這樣。補充說明,上述文件沒有提到的 PHP5 中的 Reflection API,你可以為每個函式加上 arginfo,可以方便一些工具自動取出這些 API 來用,作法請參考 Christian WeiskeHacking PHP5

另外一個值得一提的是做 Unit Testing 的方法,養成寫 test case 是維持軟體品質的好習慣。你若用了 phpize,系統應會自動生成 run-tests.php 等自動測試工具,你可以依照其設計寫一些自動測試的案例,每次編譯後可 make test 做自動測試,確保運作正常。在 IBM developerWorks 上有一篇淺析 PHP 官方自動化測試方法,值得一讀。

最後補充一點,這次我寫的延伸函式庫乃是 C 語言,若欲整合物件導向的  C++ 函式庫,可參考 Wrapping C++ Classes in a PHP Extension 一文。

Last weekend (2009 10/17~10/18), I went to Yahoo Open Hack Day Taiwan. The event seems has been become a big PR issue of Yahoo, only because a few minutes of lap dance.

Before I talked about what I feel about lap dance as a developer joined this event, I like to share about what we did in this event. As a team with hychen, tusng and honki, we were thinking about implement a self-learning web site, which provides a bookmarklet or plugin to let you look up the English words. And also help you to convert unfamiliar word on computer into physical flash card. But after we got there, we found this web site does not really use any Yahoo!API. :p

So, we pick up another idea from my never-have-time-to-start TODO list. We called it Synker,the original idea is to help people sync photos from any social network website into their own Google/Yahoo contacts. But we don’t want to have an avatar, we like to have photos with really face of our contacts. So we only use photos with face identified by integrated face detection technology. If you use these contact services on your phone, you will find it extremely useful when you try to remember someone when he/she calls.

After changed the idea, we start to implement it at Saturday afternoon. And finally we do can login with Yahoo account, download the contacts and find possible photo from Wretch profile and albums. It’s quite slow but it works. We tried to find Wretch girls hired by Yahoo as staffs to be our beta testers, it turns out that much of people don’t really use Yahoo! Contacts or Yahoo!360 lately. So most of the contacts are added very long time ago when YIM is still popular in Taiwan. For the local Wretch users, it might be much more useful if we can help them link their wretch users back to Yahoo contacts. However, Synker should be a service to help people sync photo into different contact service, the web site is now still a prototype, we might finish it later when we are available.

However, we did not win any award. Thanks to Erik Eldridge, at least we are mentioned in his favorite hacks list. But still, I have a lot of fun work with my teammate to implement a web site from scratch. I do enjoy to get tired, beard grown and smelly with friends after a non-stop 24 hours hacking. It’s exciting to experience issue and fix them together. It’s fun and we never stop laughing.

Thanks to Yahoo for organized this event. Without this event, I probably won’t get any chance to study Yahoo!APIs, and work with my friends on these APIs all day long. Thanks!

Sexism ?

So, many people feels women are offended, and they said sexism is bad for creating an inclusive environment in industry. I have to say please don’t judge the organizer before you understand the local culture. Applying your own viewpoints to the other side of earth is globalism, which does not help to create an inclusive environment.

As a developer staying there for the whole event, I don’t see the any lady are offended. But we, the shyly nerds are probably more insulted. :p

One my the other female friend XDite, she has been attend to Yahoo Open Hack Day since last year. She has same feeling as I do, we don’t feel it’s offending women. The dancing show is only a few minutes. We disliked it because it’s very annoyed for developers, since we have been coding for hours, a loudly music and dancing show just make us headache. It’s just annoying as the anchorwoman made some stupid jokes and asked developers to dance before the warding ceremony. It’s perhaps humiliated us much more then the dance girls.

Seriously, No! There are many female staffs around and many of the many of the top managers of Yahoo!Kimo Taiwan are female! And also the other female members in the other team. I don’t see there is any sexism issue in Yahoo and this event. However, I can understand why they like to have the dancing show, one for cheer the developers up after long time work, the other reason is to satisfy the local sick mass media.

The dancing show is only a few minutes, not the major part of the event. And we don’t care about the show, since we are really busy on get the things work. And yes, the kind of entertainments are expected in many IT events. It might comes from the history of southerns Taiwanese funerals and temple fair. People think it’s important to entertain Spirits, and living people, so they hire strippers to dance in public. It’s a symbol of supplicatory.

And somewhat this kind of traditions infected the IT event, but much more refined. Now, without Show Girls in a IT event, you will never get reported on local mainstream media. And this kind of tradition are spread in the world, which you can see many show girls on the online IT web sites.

It’s now become yet another industry for provide profession performing in IT events (commercial IT events does not mean open source software conference or hackathon). In addition, the dancing girl are professional dancers, they are not just boob girls or some woman found from the strip club. They are payed as profession for performing. I meant is creating something with your mind is much respectable then creatively with the body ? And what’s wrong that these ladies choose dancing as profession, is that one of talents should be appreciated ?

If you ask my opinion, I dislike this kind of arrangement it’s because it disturbed me. And don’t blame Yahoo, it’s totally not an issue of sexism of the event, you idiot. It’s about the sicked (local and global) media. Please go fight with the mainstream media if you think they are sexist, and many Taiwanese are already doing so.

去年年中試用過 Adobe AIR for Linux beta 後,從去年年底 Adobe 發行1.0 正式 版,一直都沒有安裝新版。剛剛又再度試玩一下,比較有趣的是,Adobe AIR 跟系統本身的軟體套件管理系統高度整合,例如你裝了一個新的 Adobe AIR 軟體時,他會自動封裝並安裝成 dpkg ,於是你若使用一般的套件軟體管理工具如 aptitude / synaptic 也可以移除 Adobe AIR 軟體。

之前提到的 Adobe AIR XIM 問題已經修正 (當初回報的論壇文章已經被刪掉 ?!),至少在 twhirl 下可以正常輸入中文,不過一併測試了 Balsamiq Studios 的好用軟體打樣工具 Balsamiq Mockup,結果發現這個工具還是無法接受 scim 的中文輸入,真可惜,只好繼續用英文設計版面。相較於其他的軟體版面打樣軟體,Balsamiq Mockup 算是最直覺簡單的一套,而且隨便拉一拉做出來的成果還算美觀,有手繪筆記的風格。在 Mockups To Go 上,還有不少人分享設計樣板可供參考。

若是想嘗試更多的 Adobe AIR 軟體,Adobe 建了一個 Marketplace,可以直接下載安裝不同的軟體,許多軟體都是免費授權使用的。

身為一個兼職網管,偶爾你總想找出到底是那一隻程式佔用了網路埠、或是找出某個連線是哪隻程式建立的。在 FreeBSD 上有一個工具非常好用,叫做 sockstat。但是 Linux 過去一直沒有人寫這樣的工具,你可以用 ‘lsof -i -n’ 或是 ‘netstat -anpe‘ 等指令來滿足這個需求。

最近 William Pitcock (nenolod) 重新改寫了一版給 Linux 用的 sockstat,目前已經進入 Debian Sid 中。

需要者請自行取用吧。

Continue reading

Have you experienced that the useful ScribeFire (a nice WYSIWYG blog tool for firefox extenstion) crashed, and you lost the latest post which you just wrote for a few hours ?

If the answer is yes, and you are using ScribeFire 2.3.2 and restart the Firefox and visit this blog for searching how to recover your hard work.

I am sorry to tell you, it’s too late, your work is overwritten.

If you did not restart the browser and lunch the ScribeFire, then you got luck. Backup the performancing-notes.xml file in your firefox/profile/extensions as soon as possible, it’s your latest chance to save it.

The problem is because the ScribeFire editor does not save the editor state by autosave, when the firefox crashed. And it will use the old content in editor state to overwrote your latest ‘saved work‘.

This is a small but very annoying issue, which break your hard work. Hope it will be fixed very soon. You can find a workaround patch in Issue 714 of ScribeFire’s issue list system.

Flash Player 9 後又過了一年半,Adobe 終於又將發行支援 Linux 的 Flash Player 10

新版的 Flash 在各種多媒體處理的能力與效能上都有重大的改進。包含了新的 繪圖/3D API、新的音效處理 API,在 Linux 平台上尚新增了以下功能

  • Linux WMODE (windowless mode)
  • Video4Linux v2 Support
  • unloadAndStop
  • Limited Fullscreen Keyboard Access
  • File Reference runtime access
  • Dynamic Sound Generation
  • Large Bitmap Support
  • Context Menu
  • GB18030 Compliance
  • Ubuntu OS Support

終於,Flash 不會老是浮起來蓋住 HTML。當然,我最關心的其中一個功能是新的 Flash Player 支援 v4l2,於是我終於有機會不需靠 Flashcam 或 patch libflashsupport.c 使用 Webcam,可以開始玩 Yahoo Live, wooMeseesmic 等網站。

但稍微測試了一下還是有些問題。Flash 似乎無法與我使用的 uvcvideo 融洽相處,總是會再抓了一張 frame 後抱怨 ‘Camera is unavailable, may be in use by another application‘。目前測試的版本是 Flash Player 10 Beta2,希望正式版發行前可以修正這個問題

另外一個令人感興趣的功能是,在新的 Flash 10 的 Release Note 中提到了 RTMFP,與 RTMP 不同的是,RTMFP 是以 UDP 為基礎的 P2P 通訊協定。根據 Release Note 中的敘述,這項技術來自 Adobe 於 2006 所收購的 Amicima 公司,在 RTMFP FAQ 中有稍微詳細的技術說明。以目前的技術規格來看,雖然無法做到類似 Bittorrnet 的 P2P Swarming 來作檔案分享。但是可以拿來作點對點的通訊協定替代品,對於建立像 wooMe 這樣的服務來講,可以省下大量的頻寬才是。