網頁

2013年6月7日

Install PHP libeio

If you get some warning message, try this command
pecl install channel://pecl.php.net/eio

After install libevent, remember to modify php.ini, add this line
extension=eio.so
You can use this command to check if php already enable libevent
php -m | grep eio

2013年6月6日

Ubuntu 系统 Update-rc.d 命令

原文:Ubuntu 系统 Update-rc.d 命令

Ubuntu或者Debian系统中update-rc.d命令,是用来更新系统启动项的脚本。这些脚本的链接位于/etc/rcN.d/目录,对应脚本位于/etc/init.d/目录。在了解update-rc.d命令之前,你需要知道的是有关Linux 系统主要启动步骤,以及Ubuntu中运行级别的知识。

Linux 系统主要启动步骤

  1. 读取 MBR 的信息,启动 Boot Manager。
  2. 加载系统内核,启动 init 进程, init 进程是 Linux 的根进程,所有的系统进程都是它的子进程。
  3. init 进程读取 /etc/inittab 文件中的信息,并进入预设的运行级别。通常情况下 /etc/rcS.d/ 目录下的启动脚本首先被执行,然后是/etc/rcN.d/ 目录。
  4. 根据 /etc/rcS.d/ 文件夹中对应的脚本启动 Xwindow 服务器 xorg,Xwindow 为 Linux 下的图形用户界面系统。
  5. 启动登录管理器,等待用户登录。

Install PHP libevent

Install libevent core library
apt-get install libevent-dev

you will need to install PEAR via apt-get to get the necessary package and distribution system that both PEAR and PECL use.
apt-get install php-pear
Now you will need to install the php5-dev package to get the necessary PHP5 source files to compile additional modules
pecl install libevent
If you get some warning message, try this command
pecl install channel://pecl.php.net/libevent-0.1.0

After install libevent, remember to modify php.ini, add this line
extension=libevent.so
You can use this command to check if php already enable libevent
php -m | grep libevent

2013年5月25日

Timezone problem

目前遇到 timezone 設定上的問題,大致上是這樣的。

如果有一個全球性的網站,網站上面會顯示時間,時間必須以 local time 表示。那麼,DB、PHP 裡的 timezone 應該怎麼設定呢?一般在台灣安裝的 DB、PHP 都是以 Asia/Taipei 都做 timezone 設定,也就是 GMT+8。

但是轉換到其他的 local time 時,就顯得不夠直覺。所以目前的想法是將全部都設定成 GMT+0,當作一個標準的時間。然後根據使用者的環境,轉換到使用者的 local time 。

Postgres

/etc/postgresql/9.1/main/postgresql.conf
timezone = GMT+0’
/etc/init.d/postgresql restart

PHP

新增一個 ini 檔案,放到 /etc/php5/conf.d/ 路徑下
/etc/php5/conf.d/timezone.ini
date.timezone = "GMT+0"
/etc/init.d/apache2 restart

User Timezone

使用者的 timezone 實作上有多種方法,因為要知道使用者的 timezone 是一件滿困難的事情,另外就是準確度的問題。

1. GIO IP。透過使用者的 ip 做定位,然後轉換成對應的 timezone。這種方法會遇到準確度的問題。

2. 寫AJAX CODE,讀取 Browsr 的 time 傳回給server,然後由server 判斷時間差了多久。間接猜測使用者的 timezone。

3. 在網頁上開一個設定頁面,讓使用者設定 prefer timezone,server 依靠這個值轉換出正確的 local time。

2013年5月19日

Accurate Regex Pattern for Matching URLs

Original: An Improved Liberal, Accurate Regex Pattern for Matching URLs
Test Data: http://daringfireball.net/misc/2010/07/url-matching-regex-test-data.text

這一篇文章的版權屬於原作者,這裡只是做個程式上的學習記錄。

因為最近在開發wall script,可以讓使用者在 textarea 中輸入一段文字,假如文字中遇到 url pattern,後端的 php 可以自動幫 url 加上 anchor tag。之後顯示在覽劉器中,就會自動變成一個超連結了。

問題的描述滿簡單的,但是要怎樣判斷 url ,就變得十分的棘手。遍尋網路上的一些解答,以目前這一篇的解法最有邏輯性,可以根據這邊的邏輯,修改成自己適合的樣式。

因此特地將這個作者的文章給記錄下來,以防以後連結不見的憾事。