Joe Horn 的啟示錄
Joe Horn's Blog
  • LinkedIn
  • Facebook
  • Instagram
  • GitHub
  • Docker Hub
RSS
  • VPS Referrals
  • My Plurk
  • My Plurk Bot

9 月 5 2013

PHP 樣板引擎(templating engines)

翻文件翻到這篇。
雖然時間有點久了(2009 年的文章),但我覺得該文仍具參考價值。

該文裡面提到了一些樣板引擎;排除已經不存在的 Calypso,目前仍存在的有這些:

  • Smarty
  • PHPTAL
  • eZ Components 的 Template
  • Dwoo
  • Twig

該文作者沒提到 Template Lite、Zend View,倒是給了些數據。

網路上有許多 Smarty 2、Smarty 3、Dwoo 的效能評測資訊,由快至慢列舉的話,幾乎都是 Dwoo -> Smarty 2 -> Smarty 3。
但是 Dwoo 已經宣告 EOL 了。官方網站直接放上這段文字:

Important Notice – Dwoo End Of Life
This library is not being maintained anymore for quite a while, so if you are starting a new project you should consider using Twig instead.

Twig 官方的安裝文件給了數種安裝方式,不知道文章作者用的是哪一種。 O_o
( 如果是 compile 成 PHP extension 的話,效能肯定是比較好的呀… )

PS. Twig 的 for … in … 挺有趣啊,我看到 Perl 的影子。 XD

By Joe Horn • PHP 1 • Tags: benchmark, Dwoo, eZ Components, PHP, PHPTAL, Smarty, templating engine, Twig

8 月 29 2013

[FreeBSD] 讓 Postfix 使用 Gmail 的 SMTP server 送信

數月前,我在 Amazon EC2 開了一個跑 FreeBSD 的 Micro Instance 來 maintain ports。
我認為這台虛擬機器隨時都可以重造,所以我在 Security Groups 的設定中只幫 Inbound 綁了幾個特定的 IP,讓我可以 ssh 登入就好。
於是我就讓這台虛擬機器跑 Postfix,透過 gmail 的 SMTP server 幫我送 PR 。

目前在網路上找到的說明,大多都會提到 SSL/TLS certificate 的設定,我倒是跳過了這段,而且就目前看來是運作良好。
步驟大致如下:

  1. 用以下指令作 Postfix 的編譯設定:
    # cd /usr/ports/mail/postfix && make config

    其中 TLS 選項一定要勾。

  2. 安裝(或重新安裝) postfix。
  3. 在 /usr/local/etc/postfix/main.cf 放進以下的設定:
    relayhost = smtp.gmail.com:587
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/usr/local/etc/postfix/gmail_passwd
    smtp_sasl_security_options =
    smtp_use_tls = yes
    
  4. 編輯 /usr/local/etc/postfix/gmail_passwd ,內容大致如下(記得填上自己的 gmail 帳號與密碼):
    smtp.gmail.com:587 帳號@gmail.com:密碼
  5. 用以下指令製作 hash map:
    # postmap /usr/local/etc/postfix/gmail_passwd
  6. 啟動(或重新啟動)Postfix:
    # /usr/local/etc/rc.d/postfix restart

PS1. 以上的設定只適合單人用機,因為所有外寄的郵件都會透過同一個 gmail 位址寄出。 :p
PS2. 記得刪掉 /usr/local/etc/postfix/gmail_passwd ,或是作 chmod 。

By Joe Horn • FreeBSD, Mail 0 • Tags: FreeBSD, Gmail, Postfix

8 月 5 2013

[Ubuntu] 安裝 & 設定 libapache2-mod-auth-mysql

這兩天試著在 Ubuntu server 玩 Apache HTTP authentication with MySQL backend 。
記一下幾個要注意的地方:

  • 設定參數在 /usr/share/doc/libapache2-mod-auth-mysql/DIRECTIVES.gz ,可以透過以下這個指令查:
    # dpkg-query --listfiles libapache2-mod-auth-mysql
    
  • 為避免 Apache 混合使用驗證而導致驗證失敗,加上這行比較保險:
    AuthBasicAuthoritative Off
    

.htaccess 檔內容大概像這樣:

AuthName "JoeHorn's Secret Web"
AuthType Basic
AuthBasicAuthoritative Off
AuthUserFile /dev/null
Auth_MySQL on
Auth_MySQL_User DB_USERNAME
Auth_MySQL_Password DB_PASSWORD
Auth_MySQL_DB AUTH_INFO_DB
Auth_MySQL_Password_Table AUTH_INFO_TABLE
Auth_MySQL_Username_Field USERNAME_FIELD
Auth_MySQL_Password_Field PASSWORD_FIELD
Auth_MySQL_Empty_Passwords off
Auth_MySQL_Encryption_Types MySQL
Require valid-user

By Joe Horn • Linux 0 • Tags: Apache, htaccess, HTTP_AUTH, MySQL, Ubuntu

7 月 5 2013

Subversion 1.8

Subversion 1.8 又更改 client 端的 metadata 結構了… orz

1.7 的結構如下:

1.8 則是長這樣:

差異就是… 原本獨立用純文字檔紀錄的 format 跟 entries 被整併到 wc.db 了。
( 而 wc.db 是 SQLite 的資料庫檔 )

PS. 我在用的 NetBeans 7.3.1 尚未支援新結構,所以出來唉唉叫一下… (死

By Joe Horn • Computer Software 0 • Tags: NetBeans, Subversion, SVN

1 月 10 2013

[PHP] foreach() 會踩到的陷阱 ( bug ? )

今天在公司處理某支程式時,發現使用 PHP 的 foreach() 可能會踩到這個陷阱(或許算是 bug ?! O_o )。

以下這段範例程式,結果是正確的。

<?php
$arr = array();

array_push( $arr , 1 );
array_push( $arr , 2 );
array_push( $arr , 3 );

$arr['a'] = 'A';
$arr['b'] = 'B';
$arr['c'] = 'C';

foreach ( $arr as $k => $v ) {
	echo "$k => $v" . PHP_EOL;
}
?>

結果:

0 => 1
1 => 2
2 => 3
a => A
b => B
c => C

但下面這段範例程式的結果就很妙了…

<?php
$arr = array();

array_push( $arr , 1 );
array_push( $arr , 2 );
array_push( $arr , 3 );

$arr['a'] = 'A';
$arr['b'] = 'B';
$arr['c'] = 'C';

foreach ( $arr as $k => $v ) {
	if ( $k == 'b' ) {
		echo "$k => $v" . PHP_EOL;
	}
	if ( $k === 'b' ) {
		echo "$k ==> $v" . PHP_EOL;
	}
}
?>

結果:

0 => 1
b => B
b ==> B

By Joe Horn • PHP 4 • Tags: foreach, PHP

12 月 25 2012

[Ext JS] Ext.form.field.Text 的 emptyText

為了給使用者更多的提示,讓使用者順利完成表單,我們會在 web 表單的 text 欄位使用如下的語法:

<input type="text" value="Search keyword(s)" name="s" id="s"
       onfocus="if (this.value == 'Search keyword(s)') {this.value = '';}"
       onblur="if (this.value == '') {this.value = 'Search keyword(s)';}" />

在 Ext JS ,則是透過 Ext.form.field.Text 的 emptyText 來實作此一效果:

Ext.create('Ext.form.field.Text', {
	id: 's' ,
	name: 's' ,
	emptyText: 'Search keyword(s)'
});

Ext JS 已經開始使用 HTML5 的語法,所以在部份瀏覽器上, Ext JS 改用 input 的 placeholder 屬性來實作;根據說明,該屬性應有相同效果,與 onfocus、onblur 作連動。
但在 Ext JS 4.1.0,已經設定 emptyText 的 Ext.form.field.Text 元件卻不會在滑鼠點選後清空文字。

目前的解法是讓 Ext JS 捨棄 placeholder 的實作;方法如下:

Ext.onReady( function() {
	Ext.supports.Placeholder = false;
	....
});

By Joe Horn • Javascript, WWW 0 • Tags: emptyText, Ext JS, HTML5, Javascript, onblur, onfocus, placeholder, textfield

12 月 14 2012

WordPress 3.5 released

從官方的 Blog 文章跟影片看來,主要是支援了多媒體的大量/批次上傳。

若從 3.4.2 升級到 3.5 的話,以下這些檔案可以刪除…

More

By Joe Horn • WordPress 0 • Tags: Elvin, WordPress

3 月 13 2012

在 FreeBSD 用 ports 安裝 MySQL 5.5

我在 FreeBSD 用 ports 安裝 databases/mysql41-server 、 databases/mysql50-server 時,會放這些 configuration parameters:

  • WITH_CHARSET=big5
  • WITH_XCHARSET=all
  • BUILD_OPTIMIZED

(databases/mysql51-server 會多放個 WITH_FAST_MUTEXES)

之前要安裝 databases/mysql55-server 時發現…
databases/mysql55-server 只剩下 WITHOUT_OPENSSL 與 WITH_FASTMTX 這兩個 configuration parameters 可以用,而預設的 WITH_EXTRA_CHARSETS(文章前頭提到的 WITH_XCHARSET)就是 all;以往使用的 WITH_CHARSET=big5 必須從 my.cnf 作設定(這也的確是比較好的作法);BUILD_OPTIMIZED 則是不需要了(也不支援?)。

另外,databases/mysql55-server 預設只有這些 storage engines:

mysql> SHOW ENGINES;
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| Engine             | Support | Comment                                                    | Transactions | XA   | Savepoints |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
| MRG_MYISAM         | YES     | Collection of identical MyISAM tables                      | NO           | NO   | NO         |
| CSV                | YES     | CSV storage engine                                         | NO           | NO   | NO         |
| MyISAM             | DEFAULT | MyISAM storage engine                                      | NO           | NO   | NO         |
| InnoDB             | YES     | Supports transactions, row-level locking, and foreign keys | YES          | YES  | YES        |
| PERFORMANCE_SCHEMA | YES     | Performance Schema                                         | NO           | NO   | NO         |
| MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables  | NO           | NO   | NO         |
+--------------------+---------+------------------------------------------------------------+--------------+------+------------+
6 rows in set (0.00 sec)

ARCHIVE、BLACKHOLE、EXAMPLE 跟 FEDERATED 這四個 storage engines 可以透過 INSTALL PLUGIN 的方式進行安裝,例:

mysql> INSTALL PLUGIN archive SONAME 'ha_archive.so';
mysql> INSTALL PLUGIN blackhole SONAME 'ha_blackhole.so';
mysql> INSTALL PLUGIN example SONAME 'ha_example.so';
mysql> INSTALL PLUGIN federated SONAME 'ha_federated.so';

By Joe Horn • Database, FreeBSD 0 • Tags: FreeBSD, MySQL, ports

3 月 7 2012

Free slave name server services

roga 在幾天前開了 topDN.net 提供免費/付費的 domain name hosting 服務。

實際上,在台灣的 domain name registrar 幾乎都提供類似的服務,但公開讓大家使用的 slave name server 服務倒是還沒在台灣出現(印象中是這樣,至少我還沒看過)。

絕大多數的 internet services 都應該佈署 secondary/slave server,像 DNS、E-Mail、WWW。
而且,secondary/slave server 應與 primary/master server 使用不同的網路(ISP),把機器放在不同的地點。

Anyway,有需要 slave name server 服務的人,可以參考這些網站(依照 domain 排序,無優劣之分):

  • http://www.buddyns.com/
  • http://dns.he.net/
  • https://puck.nether.net/dns/
  • http://twisted4life.com/index.php
  • http://xname.org/

By Joe Horn • Network 0 • Tags: DNS, domain name, name server

3 月 2 2012

MySQL 的 max key length

我曾試著在 MYISAM 格式的 table 裡,把兩個 VARCHAR(255),UTF8 編碼的欄位設定成一組 UNIQUE KEY。
當時遇到這個 Error:

#1071 – Specified key was too long; max key length is 1000 bytes

VARCHAR(255) 代表該欄位可以紀錄 255 個字元,每個字元以 UTF8 encoded 儲存,一個欄位可以佔用 765 bytes,所以兩個欄位總和超過 1000 bytes,無法設為一組 UNIQUE KEY。

前陣子,我把 MySQL 從 5.1 系列升版到 5.5 系列。
在 5.1(含)之前,MySQL 使用 3 個 bytes 紀錄 UTF8 encoded data。
開發團隊在 MySQL 5.5.3 加入了 utf8mb4 編碼,用 4 個 bytes 紀錄 UTF8 encoded data,支援更多的文字。

utf8mb4 讓我聯想到 max key length 的問題,所以進行了一些小測試,並追了一下 source code。
從目前的最新版本的 source code 看來:

  • MySQL 5.0.95 的 MAX_KEY_LENGTH 依然是 1000 bytes。
  • MySQL 5.1.61 的 MAX_KEY_LENGTH 是 3072 bytes。
  • MySQL 5.5.20 的 MAX_KEY_LENGTH 是 3072 bytes。

By Joe Horn • Database 0 • Tags: MySQL

«‹ 4 5 6 7›»

Site Info

All content on this Blog is licensed under CC BY-NC-SA 4.0

About Me

profile for Joe Horn at Stack Overflow, Q&A for professional and enthusiast programmers


My mail!

獅子座

Coffee Powered!

F1 fans

motoGP fans

Linkin Park

I am a Taiwanese!

Recent Comments

  • Avatar of johnpupu johnpupu: PHP 還有這個 phpsavant.c……
  • Avatar of Jerry Jerry: 这个不是foreach的问题。 0 ==……
  • Avatar of Joe Horn Joe Horn: 看來問題在 if ... else ..……
  • Avatar of jnlin jnlin: 因為 'b' 被轉型成 0 了…
  • Avatar of 路人 路人: 跟 foreach 沒有關係 ?…
  • Avatar of bill bill: 註冊表那裡要設定 BasicAuthLe……
  • Avatar of 虫 虫: .svn 的檔案減少可以增加在 wind……
  • Avatar of mars mars: 如果說寫程式是理性極致的話,那寫小說就是……
  • Avatar of Joe Horn Joe Horn: 已更新文章。…
  • Avatar of jackcal jackcal: joehorn.idv.tw關於轉貼 h……

Post Categories

  • About My Sites (16)
  • Computer Hardware (28)
  • Computer Software (45)
  • Database (23)
  • FreeBSD (21)
  • Funny (14)
  • Life (23)
  • Linux (5)
  • Mail (19)
  • Network (12)
  • Programing (40)
    • .NET (5)
    • JAVA (2)
    • Javascript (6)
    • PHP (29)
  • Thoughts (34)
  • Windows (13)
  • WWW (79)
    • phpBB (7)
    • WordPress (18)

Blogroll

  • 這裡沒有美食

Tags Cloud

AMD Apache benchmarking Bloglines Coppermine DNSBL eAccelerator fio Firefox free FreeBSD Gmail Google HDD Hsin-chu HTTPS IE Intel Javascript Lenovo Longhorn Microsoft MSN MySQL Office Percona XtraBackup performance PHP phpBB pirate Postfix restaurant RSS security sendmail software SpamAssassin SSL Subversion Taiwan theme translation Windows WordPress Yahoo

Ads

↑

© Joe Horn 的啟示錄 2025
Powered by WordPress • Themify WordPress Themes