SDpower

PHP 5.3.3 FreeBSD 安裝調整.

by admin on 八月.10, 2010, under FreeBSD, PHP & MYSQL

php 5.3.3之後整合了php-fpm進去對於使用輕量化web server的使用者不再麻煩了.
以下是安裝畫面,安裝選項.

# cd /usr/ports/lang/php5; make install clean;


(continue reading…)

Leave a Comment more...

FreeBSD 上使用 wkhtmltopdf 做網頁擷取

by admin on 八月.04, 2010, under FreeBSD, PHP & MYSQL

以往要用程式控制將網頁輸出pdf或擷取網頁,都是件浩大工程.
這次介紹如何在FreeBSD 命令列模式下即可輕易辦到,並且不需龐大的X Windows 圖形系統適合在server上跑.

以下是軟體原文介紹.

wkhtmltopdf

Convert html to pdf using webkit (qtwebkit)

Description

Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.

Introduction

Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.
此軟體使用WebKit開發完成,除了flash以外其他接可正常顯示!!(包含js)
在安裝前請先確定你的FreeBSD已安裝 linux-base 套件並正常使用,並且將port tree更新.
(continue reading…)

Leave a Comment more...

micro 2440 遠端rs232 控制

by admin on 五月.11, 2010, under Embedded, micro 2440

想法:

一般使用rs232 over ip 的硬體都不便宜,此次想法將micro 2440版子上的com 1 可以以網路連接方式使用.

而且依照arm 2440這棵cpu來說此次任務實在太簡單,元比單買硬體的rs232 over ip硬體來的方便快速 市面上的rs232 over ip硬體的mcu效能無從的知.

達成server端 不論在美國 或是我加隔壁都可以透過網路做rs232開發控制.

實作狀況:

找了許久找到http://lpccomp.bc.ca/ 的 http://lpccomp.bc.ca/remserial/index.html

功能The remserial program acts as a communications bridge between a TCP/IP network port and a Linux device such as a serial port. Any character-oriented Linux /dev device will work.

嗯這功能就是我需要的

在另外一台linux pc  編譯給arm用的執行檔

# wget http://lpccomp.bc.ca/remserial/remserial-1.4.tar.gz
# tar zxvf remserial-1.4.tar.gz
#cd remserial-1.4
#make CC=/opt/toolchains/arm920t-eabi/bin/arm-linux-gcc CPP=/opt/toolchains/arm920t-eabi/bin/arm-linux-g++
<a href="http://blog.sd.idv.tw/wp-content/uploads/2010/05/remserial.zip">remserial</a>

最後將 remserial 存到sdcard傳到版子上 /usr/local/bin

在板子的consol端下指令

#remserial -d -p 23000 -s "115200 raw" /dev/ttySAC1

這段意思 將com1 /dev/ttySAC1 以115200胞率raw模式  轉移到 port 23000

為了試驗測試 我將com0 與com1 用有跳線的連接線連接,com0為板子的預設consol端 如果此次運作正常 我就可以透過網路操作.

PC端連線:

使用xp內建的超級終端機

連線方式選擇

選擇TCP/IP 並輸入連線主機還有port 依照先前執行的命令 port設定為23000

YA!!按一下enter馬上送出 反應之快(區域網路當然快)

心得:

以往在做工業控制或開發等使用到rs232時 都必須接線重要的是終端設備 不能離主機很遠….(很大困擾)

想想看如果你的廠房有10台機器要控制,每台機器旁邊都要有pc做主控這樣不是一個很大成本

現在透過過網路(也可以使用無線網路,連網路線的布線維護都省下)員工只要坐在辦公室 操作電腦

一台pc還可以直接控制 上百台設備都不是問題 !! 老闆在國外也可以連線回廠區做控制設定!!

備註:

http://www.dest-unreach.org/socat/  一個可以在linux做i/o導向轉址 可以研究看看

remserial

Leave a Comment more...

micro 2440 開箱 & Embedded Linux 初見面

by admin on 五月.11, 2010, under Embedded, micro 2440

micro 2440

簡介:(官網簡介)

如圖為 Micro2440 核心板佈局圖,它採用6 層板設計,並使用等長布線以滿足信號完
整性要求。從調試開發和方便維修的角度,我們把主要芯片均放置在頂層。為了方便拔插和
引出更多的CPU 信號腳,核心板採用2.0mm 間距「U」型排列插針,故我們也經常把它簡稱
為「U」型核心板-U2440。
Micro2440 其實是一個最小系統板,它包含最基本的電源電路(5V 供電)、復位電路、
標準JTAG 調試口、用戶調試指示燈、以及核心的CPU 和存儲單元等。其中FLASH 存儲單
元包含NAND FLASH 和NOR FLASH 兩種類型,通過跳線J1 可以選擇從NAND 或NOR 啟
動系統。一般NOR FLASH 裡面放置的是不經常更改的BIOS(我們採用的是supervivi),NAND
FLASH 裡面則燒寫完整的系統程序(bootloader、內核、文件系統等)。

Micro2440 的具體硬件資源特性:

CPU
- Samsung S3C2440A,主頻400MHz,最高533Mhz
SDRAM
- 在板64M SDRAM
- 32bit 數據總線
- SDRAM 時鐘頻率高達100MHz
Flash Memory
- 在板256M Nand Flash, 掉電非易失,可根據客戶要求更高為為64M-1G
- 在板2M Nor Flash,掉電非易失,已經安裝BIOS
接口和資源
- 1 個56 Pin 2.0mm 間距GPIO 接口PA
- 1 個50Pin 2.0mm 間距LCD CMOS CAMERA 接口PB
- 1 個56 Pin 2.0mm 間距系統總線接口PC
- 在板復位電路
- 在板10Pin 2.0mm 間距JTAG 接口
- 4 個用戶調試燈
系統時鐘源
- 12M 無源晶振
實時時鐘
- 內部實時時鐘(需另接備份鋰電池)
系統供電
- +5V
尺寸
- 63 x 52 mm

Micro2440SDK 底板佈局及接口資源如下圖所示,它是一個雙層電路板,為了方便用
戶學習開發參考使用,上面引出了常見的各種接口,並且大部分都集中在電路板一側,多餘
的IO 口和系統總線則通過2.0mm 間距的插針引出。

Micro2440SDK 底板資源特性:
* 1 個100M 網絡RJ-45 接口,採用DM9000 網卡芯片
* 3 個串口接口,分別有RS232 接口和TTL 接口引出
* 4 個USB Host(使用USB 1.1 協議),通過USB HUB 芯片擴展
* 1 個USB Slave(使用USB 1.1 協議)
* 標準音頻輸出接口,在板麥克風(MIC)
* 1 個PWM 控制蜂鳴器
* 1 個可調電阻接W1,用於AD 轉換測試
* 6 個用戶按鍵,並通過排針座引出,可作為其他用途。
* 1 個標準SD 卡座
* 2 個LCD 接口座,其中LCD1 為41Pin 0.5mm 間距貼片接口,可直接連接本公司提
供的真彩屏顯示模塊或者VGA 轉接板,另一個LCD 接口適合直接連接群創
7」LCD。
* 2 個觸摸屏接口,分別有2.0mm 和2.54 間距兩種,實際它們的定義都是相同的,
* 1 個CMOS 攝像頭接口(CON4),為20Pin 2.0mm 間距插針,可直接連接本公司的
CAM130 攝像頭模塊。
* 在板RTC 備份電池
* 1 個電源輸入口,+5V 供電
主要接口定義:
Micro2440SDK 參考底板除了常見的標準接口:音頻輸入和輸出、DB9 串口COM0,
COM1、COM2、USB Host 和 USB Slave、RJ-45 網絡接口、SD 卡座等,為了方便學習開發,
還引出了其他GPIO、系統總線接口等外設和接口,它們的名稱及定義說明請在手冊中查詢。

mini 2440 簡介:

Mini2440 開發板硬件資源特性

CPU 處理器
- Samsung S3C2440A,主頻400MHz,最高533Mhz
SDRAM 內存
- 在板64M SDRAM
- 32bit 數據總線
- SDRAM 時鐘頻率高達100MHz
FLASH 存儲
在板 256M/1GB Nand Flash, 掉電非易失(用戶可定製64M/128M/256M/512M/1G)
在板2M Nor Flash,掉電非易失,已經安裝BIOS
LCD 顯示
- 板上集成4 線電阻式觸摸屏接口,可以直接連接四線電阻觸摸屏
- 支持黑白、4 級灰度、16 級灰度、256 色、4096 色STN 液晶屏,尺寸從3.5 寸到12.1 寸,屏幕分辨率可
以達到1024×768 像素;
- 支持黑白、4 級灰度、16 級灰度、256 色、64K 色、真彩色TFT 液晶屏,尺寸從3.5 寸到12.1 寸,屏幕
分辨率可以達到1024×768 像素;
- 標準配置為NEC 256K 色240×320/3.5 英吋TFT 真彩液晶屏,帶觸摸屏;
接口和資源
- 1 個100M 以太網RJ-45 接口(採用DM9000 網絡芯片)
- 3 個串行口
- 1 個USB Host
- 1 個USB Slave B 型接口
- 1 個SD 卡存儲接口
- 1 路立體聲音頻輸出接口,一路麥克風接口;
- 1 個2.0mm 間距10 針JTAG 接口
- 4 USER Leds
- 6 USER buttons(帶引出座)
- 1 個PWM 控制蜂鳴器
- 1 個可調電阻,用於AD 模數轉換測試
- 1 個I2C 總線AT24C08 芯片,用於I2C 總線測試
- 1 個2.0 mm 間距20pin 攝像頭接口
- 板載實時時鐘電池
- 電源接口(5V),帶電源開關和指示燈
系統時鐘源
- 12M 無源晶振
實時時鐘
- 內部實時時鐘(帶後備鋰電池)
擴展接口
1 個34 pin 2.0mmGPIO 接口
1 個40 pin 2.0mm 系統總線接口
規格尺寸
- 100 x 100(mm)
操作系統支持
- Linux2.6.32.2 + Qtopia-2.2.0
- WindowsCE.NET 6.0(R3)

緣由:

從以前接觸單晶片8051,pic…時期因對組合語言很無力,學習階段也不斷受挫,拜china大中國的強大力量 現在學習Embedded 不再如此昂貴 .

當初上拍賣網站 原本從一般的開發版…最後看到這塊寶!! 豐富的i/o與介面 可以跑win ce & linux…. 這樣這快板幾乎無所不能.

原廠又提供範例與原始碼可供參考.

最後選擇micro 2440的版子原因無他mini 2440的rs232 port已經做好了 並且usb port也比較多可以使用價錢上相差不多差幾百元而已.

照片:

拆箱…我另外買的2本書也到了

豐富的教學光碟(其實是+150才有13dvd 不過奉勸有點小基礎還是別買因為不是國語口音)

主角出現

網路 *1 USB host*2 usb slave *1 COM0 音源輸出

usb host *2   sdcard*1

com1 com2

開機畫面

主畫面 系統是Linux2.6.32.2 + Qtopia-2.2.0

用內付的demo檔案 測試運作狀況

一開始用原廠提供linux檔案 開始重新編譯核心

試做軟體編譯到版子上

運作一切順利..

查了一下 上網買了 http://shopping.pchome.com.tw/?mod=item&func=exhibit&IT_NO=DCAD1H-A09504466&SR_NO=DRAF0X&ROWNO=2
TP-LINK 54M USB2.0 無線網路卡 TL-WN321G 便宜又好用

重新編譯核心 把無線網卡的驅動rt200的取消 只選rt250/rt87 的選用 就可以正確判斷使用  開心

目前只剩usb webcam  z3xx無法直接使用輸出成檔案 尚在研究中

先這樣… byby

2 Comments more...

Zend Framework multidb 不好用我自己來 Mudb

by admin on 四月.27, 2010, under PHP & MYSQL, Zend Framework

源由

Zend Framework 的 multidb 有用過因該知道,只是可以把多跟資料庫加入連結 要用時候在拿出其中之一DB來用.
有做過大型連結資料庫的使用著因該深有同感. 你們常做的動作並不是只要拿其中之一的db來做動作.
這樣動作只有在多個不同資料庫才有用而已.(如同時存取mysql mssql ….)

改進功能

  1. 讀寫分離.
  2. 讀取輪詢,分散式負載.
  3. 多重寫入

看到這邊不知道是否有引起你很大興趣呢?

除了讀寫分離,為何還需要讀取輪詢??

一般常用的資料庫,負載平衡主要也是為了分散負載.
不過你是否有跟我一樣困擾:

  • 已經分散了db讀取,卻需要每台server去分配db作為讀取.
  • 每台server都要不同的設定檔或環境,增加mis維護成本時間(煩不煩阿).
  • 某台slave db掛點,mis還須翻找server對應的db 表作為故障排除.當下還的傷透腦筋不知派哪個db給server用

你的福音來了!!使用他每台db使用固定對應表.

此套件運作模式分為Mw & RW 兩種.

Rw模式

可以設定多個matser和多個slave.
在使用下列取的資料的db function時視為 讀取動作

public function fetchAll($sql, $bind = array(), $fetchMode = null){}
public function fetchRow($sql, $bind = array(), $fetchMode = null){}
public function fetchAssoc($sql, $bind = array()){}
public function fetchCol($sql, $bind = array()){}
public function fetchPairs($sql, $bind = array()){}
public function fetchOne($sql, $bind = array()){}

在使用下列取的資料的db function時視為 寫入動作

public function insert($table, array $bind)
public function update($table, array $bind, $where = '')
public function delete($table, $where = '')

看範例說明比較快:
檔案application.ini

; multirwdb Databse setting
autoloadernamespaces[] = "Mudb"
pluginPaths.Mudb_Application_Resource = "Mudb/Application/Resource"
resources.multirwdb.model = "Rw"
resources.multirwdb.master[] = "db1"
resources.multirwdb.master[] = "db5"
resources.multirwdb.slave[] = "db2"
resources.multirwdb.slave[] = "db3"
resources.multirwdb.slave[] = "db4"
resources.multirwdb.db.db1.adapter = "pdo_mysql"
resources.multirwdb.db.db1.host     = "localhost"
resources.multirwdb.db.db1.username = "wacow"
resources.multirwdb.db.db1.password = "123456"
resources.multirwdb.db.db1.dbname   = "wacow"
resources.multirwdb.db.db1.charset  = "UTF8"
resources.multirwdb.db.db1.profiler.enabled = true
resources.multirwdb.db.db1.profiler.class = "Zend_Db_Profiler_Firebug"
 
resources.multirwdb.db.db2.adapter = "pdo_mysql"
resources.multirwdb.db.db2.host     = "localhost"
resources.multirwdb.db.db2.username = "wacow"
resources.multirwdb.db.db2.password = "123456"
resources.multirwdb.db.db2.dbname   = "wacow"
resources.multirwdb.db.db2.charset  = "UTF8"
resources.multirwdb.db.db2.profiler.enabled = true
resources.multirwdb.db.db2.profiler.class = "Zend_Db_Profiler_Firebug"
resources.multirwdb.db.db2.default = true
 
resources.multirwdb.db.db3.adapter = "pdo_mysql"
resources.multirwdb.db.db3.host     = "localhost"
resources.multirwdb.db.db3.username = "wacow"
resources.multirwdb.db.db3.password = "123456"
resources.multirwdb.db.db3.dbname   = "wacow"
resources.multirwdb.db.db3.charset  = "UTF8"
resources.multirwdb.db.db3.profiler.enabled = true
resources.multirwdb.db.db3.profiler.class = "Zend_Db_Profiler_Firebug"
resources.multirwdb.db.db3.default = true
 
resources.multirwdb.db.db4.adapter = "pdo_mysql"
resources.multirwdb.db.db4.host     = "localhost"
resources.multirwdb.db.db4.username = "wacow"
resources.multirwdb.db.db4.password = "123456"
resources.multirwdb.db.db4.dbname   = "wacow"
resources.multirwdb.db.db4.charset  = "UTF8"
resources.multirwdb.db.db4.profiler.enabled = true
resources.multirwdb.db.db4.profiler.class = "Zend_Db_Profiler_Firebug"
resources.multirwdb.db.db4.default = true
 
resources.multirwdb.db.db5.adapter = "pdo_mysql"
resources.multirwdb.db.db5.host     = "localhost"
resources.multirwdb.db.db5.username = "wacow"
resources.multirwdb.db.db5.password = "123456"
resources.multirwdb.db.db5.dbname   = "wacow"
resources.multirwdb.db.db5.charset  = "UTF8"
resources.multirwdb.db.db5.profiler.enabled = true
resources.multirwdb.db.db5.profiler.class = "Zend_Db_Profiler_Firebug"
resources.multirwdb.db.db5.default = true

檔案Bootstrap.php

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected $_defaultDb = null;
	protected $_CacheDB = null;
	protected $_View = null;
	protected $_Customer = null;
	protected function _initDatabase() {
		if ($this->_defaultDb === null) {
			if ($this->hasPluginResource('multirwdb')) {
				$this->bootstrap('multirwdb');
				$resource = $this->getPluginResource('multirwdb');
				$this->_defaultDb = $resource->getDefaultDb();
			}elseif($this->hasPluginResource('db')){
				$this->bootstrap('db');
				$this->_defaultDb = $this->getPluginResource('db')->getDbAdapter();
			}
		}
		Zend_Registry::set('db',$this->_defaultDb);
	}
     protected function _initZFDebug() {
    if ($this->_defaultDb === null) {
			$this->_initDatabase();
    }
		$options = array(
	    	'plugins' => array(
				'Html',
				'Variables',
				'Memory',
				'Time',
				'Database' => ($this->hasPluginResource('multirwdb')) ? array('adapter' => MuDB_Db::getAllDb()) : array('adapter' => array('default' => $this->_defaultDb)),
				'File' => array('base_path' => realpath(APPLICATION_PATH . '/../')),
				'Registry',
				'Exception',
	 	));
    $debug = new ZFDebug_Controller_Plugin_Debug($options);
		$this->bootstrap('frontController');
		$frontController = $this->getResource('frontController');
		$frontController->registerPlugin($debug);
 
	}

檔案IndexController.php

<?php
class IndexController extends Zend_Controller_Action
{
    public function init()
    {
        $this->db=Zend_Registry::get('db');
    }
 
    public function indexAction()
    {
		$select_test = $this->db->select()->from('system_permissions', '*')->limit(100);
		$result = $this->db->fetchAll($select_test);
		$result = $this->db->fetchAll($select_test);
		$result = $this->db->fetchAll($select_test);
		$result = $this->db->fetchAll($select_test);
		$data= array('test' => rand(5, 15));
		$this->db->insert('test', $data);
    }
}

執行畫面解說:
在IndexController.php indexAction()下我們只是如同往常對單一的db做讀取動做.
總共做了4次,卻在不同db下查詢完成.
卻可以看到執行畫面下,自動輪詢查詢取的資料.
你是否可以發現程式設計師不用傷透腦筋去更改程式碼即可使用此套件即可完成!!
而寫入動作 $this->db->insert(‘test’, $data);
卻是對全部的MASTER做一併寫入更改!!

Mw模式

Mw模式基本上是Rw延伸
設定檔只存取master部分設定!!!
如範例檔案application.ini
只有db1 db5被引用
並將model改為Mw resources.multirwdb.model = "Mw"
而Mw模式下對db做讀取動做會做輪詢.(每個master都會輪詢等同Rw的slave)
寫入動作則一樣,全部寫入.

注意事項

不再列表的圖取寫入動作則做為對db直接的使用.
Rw模式會限制每個Slave db必須為相同的adapter,此處設限為了避免不小心混用db而渾然不知.
因為很多程式設計師select用法會而不同的資料庫而使用特殊語法.

寫入的特殊應用

而不管為Rw 或MW模式 對於寫入動作則不設限.
此方式可以實現有趣的功能 同時對不同的db來源(如同時對mssql 與mysql做同步更新 不過前提是兩邊資料表必須詳同),資料同步寫入變更!!!

總結

此套件花了近一個月修改,其中的經驗與處理模式不知是否讓你產生感慨~~
這些經驗都是爆肝來的,如有取用或發佈請保留引用來源.(檔案內並未有版權註解請隨意使用)
到這邊你以為沒了嗎???
其實還有西可以實現,如本來要加入的讀取權重(但是我不能再爆肝了 交由你吧QQ)
為何需要讀取權重??
很多系統會有開發報表等等做大量的資料處理(例如報表)
如果此時有權重分配即可像此套件的使用方式一樣不用額外定義,只需對大量的讀取另做讀取做權重區分!!

感謝收看 再會byby~~

附件檔案:Mudb.tar

1 Comment more...

Zend Framework + Smarty3 整合應用

by admin on 四月.08, 2010, under PHP & MYSQL, Zend Framework

承上篇 Zend Framework + Smarty2 + Smarty3 整合應用
我曾說過:之前有使用過ZFDebug 感受到整合便利性
所以對之前整合不甚滿意.
來看看最新版本~
將附件內的Smarty3拷貝到你的library目錄內
application.ini

autoloadernamespaces[] = "Smarty3"
pluginPaths.Smarty3_Application_Resource = "Smarty3/Application/Resource"
resources.smarty.script_path = APPLICATION_PATH "/"
resources.smarty.view_suffix = "tpl.htm"
resources.smarty.params.left_delimiter = "<%"
resources.smarty.params.right_delimiter = "%>"
resources.smarty.params.plugins_dir = APPLICATION_PATH "/lib/My/Smarty/plugins"
resources.smarty.params.compile_dir = APPLICATION_PATH "/../tmp/compiled"
resources.smarty.helper_dirs.key[] = "Zend/View/Helper"
resources.smarty.helper_dirs.value[] = "Zend_View_Helper_"
;如果將來需要自己的 View Helper ,可以放在這裡
resources.smarty.helper_dirs.key[] = "My/View/Helper"
resources.smarty.helper_dirs.value[] = "My_View_Helper_"

確認好樣板檔案格式,與目錄屬性.
然後Bootstrap.php呢???

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

你已經完成了!

這就是我要的整合~~

附件檔案:ZF_Smarty3.tar

5 Comments more...

Zend Framework + Smarty2 + Smarty3 整合應用

by admin on 四月.08, 2010, under PHP & MYSQL, Zend Framework

在你開始閱讀前請先前往鐵神:Smarty 2 整合到 Zend Framework 1.10 閱讀完畢並了解.

之前有使用過ZFDebug 感受到整合便利性,於是在整合Sarmty 時想嘗試類似方式做到方便的整合.

Smarty 2

將附件內的Smarty2拷貝到你的library目錄內
在你的application.ini加入

autoloadernamespaces[] = "Smarty2"

Bootstrap.php 範例

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
		protected function _initView(){
	        $view = new Smarty2_View_Smarty (array(
			            'scriptPath' => APPLICATION_PATH . '/',
			            'params' => array(
			                'left_delimiter' => '<%', // 改成你慣用的
			                'right_delimiter' => '%>', // 改成你慣用的
			                'plugins_dir' => APPLICATION_PATH . '/library/Smarty2/Smarty/plugins', // 自訂的 Smarty plugins 可以放這裡
			                'compile_dir' => APPLICATION_PATH . '/../tmp/compiled',
			            ),
			            'helper_dirs' => array(
			                //'My/View/Helper' => 'My_View_Helper_', // 如果將來需要自己的 View Helper ,可以放在這裡
			                'Zend/View/Helper' => 'Zend_View_Helper_'
			            ),
			        ));
 
 
	        // Controller Plugin
	        Zend_Controller_Front::getInstance()->registerPlugin(new Smarty2_Controller_Plugin_Smarty());
 
	        // View Renderer
	        Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')
	            ->setViewSuffix('tpl.htm') // 可以改成慣用的樣版副檔名
	            ->setView($view);
 
	        // Zend Layout
	        $view->layout = Zend_Layout::startMvc(array(
	            'inflectorTarget' => 'layouts/scripts/:script.:suffix',
	            'layout' => 'layout',
	            'viewSuffix' => 'tpl.htm', // 可以改成慣用的樣版副檔名
	        ))->setView($view);
	    }
}

Smarty 3

Smarty3 得特性在浙次整合並沒有發揮,只是先依照以前Smarty2的用法去用而已.
所以與Smarty 2 整合大同小異.
將附件內的Smarty3拷貝到你的library目錄內
在你的application.ini加入

autoloadernamespaces[] = "Smarty3"

Bootstrap.php 範例

<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
		protected function _initView(){
	        $view = new Smarty3_View_Smarty (array(
			            'scriptPath' => APPLICATION_PATH . '/',
			            'params' => array(
			                'left_delimiter' => '<%', // 改成你慣用的
			                'right_delimiter' => '%>', // 改成你慣用的
			                'plugins_dir' => APPLICATION_PATH . '/library/Smarty3/Smarty/plugins', // 自訂的 Smarty plugins 可以放這裡
			                'compile_dir' => APPLICATION_PATH . '/../tmp/compiled',
			            ),
			            'helper_dirs' => array(
			                //'My/View/Helper' => 'My_View_Helper_', // 如果將來需要自己的 View Helper ,可以放在這裡
			                'Zend/View/Helper' => 'Zend_View_Helper_'
			            ),
			        ));
 
 
	        // Controller Plugin
	        Zend_Controller_Front::getInstance()->registerPlugin(new Smarty3_Controller_Plugin_Smarty());
 
	        // View Renderer
	        Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer')
	            ->setViewSuffix('tpl.htm') // 可以改成慣用的樣版副檔名
	            ->setView($view);
 
	        // Zend Layout
	        $view->layout = Zend_Layout::startMvc(array(
	            'inflectorTarget' => 'layouts/scripts/:script.:suffix',
	            'layout' => 'layout',
	            'viewSuffix' => 'tpl.htm', // 可以改成慣用的樣版副檔名
	        ))->setView($view);
	    }
}

注意如果你於使用中 compile_dir目錄未建置或不可讀寫並且使用ZFDebug.會發現空白頁面並且無任何訊息.

請先參考附件架構.
附件:zf_smarty

1 Comment more...

筆記 Haproxy 設定

by admin on 四月.07, 2010, under FreeBSD

Haproxy 設定筆記

global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /var/chroot/haproxy
        user haproxy
        group haproxy
        daemon
        #debug
        #quiet
                                nbproc      2 # Number of processes
 
defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3
        option redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      30000
        srvtimeout      50000
        monitor-uri /ok.html
        stats uri /stats
        stats auth admin:admin
 
listen  load_balanced_http      :80
    mode http
    option httpchk
    option httplog
    option forwardfor
    option httpclose               # disable keep-alive
    option checkcache              # block response if set-cookie & cacheable
    option redispatch
    option persist
    cookie SERVERID insert nocache indirect
    balance roundrobin
    server shop1 192.168.0.1:80 cookie server01 weight 49 maxconn 400 check inter 40000
    server shop2 192.168.0.2:80 cookie server02 weight 51 maxconn 500 check inter 40000
 
listen  load_balanced_https     :443
    mode tcp
    balance roundrobin
    option  ssl-hello-chk
    option  forwardfor
    server shop1 192.168.0.1:443 check inter 30000 rise 1 fall 2
    server shop2 192.168.0.2:443 check backup
Leave a Comment more...

Zend Famework 1.10.3 + ZFDebug

by admin on 四月.07, 2010, under PHP & MYSQL, Zend Framework

對基本架構不了解可先前往 鐵神: http://www.jaceju.net/blog/?p=1077

此架構為快速架構起始專案的設定

application.ini 內容

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
;resources.frontController.noViewRenderer = 1
 
autoloadernamespaces[] = "ZFDebug"
;Stand Databse setting
resources.db.adapter         = "pdo_mysql"
resources.db.params.host     = "localhost"
resources.db.params.username = "wacow"
resources.db.params.password = "123456"
resources.db.params.dbname   = "wacow"
resources.db.params.charset  = "UTF8"
resources.db.params.profiler = true
;resources.db.isDefaultTableAdapter = true
; Multidb Databse setting
resources.multidb.db1.adapter = "pdo_mysql"
resources.multidb.db1.host     = "localhost"
resources.multidb.db1.username = "wacow"
resources.multidb.db1.password = "123456"
resources.multidb.db1.dbname   = "wacow"
resources.multidb.db1.charset  = "UTF8"
resources.multidb.db1.params.profiler.enabled = true
resources.multidb.db1.params.profiler.class = "Zend_Db_Profiler_Firebug"
 
resources.multidb.db2.adapter = "pdo_mysql"
resources.multidb.db2.host     = "localhost"
resources.multidb.db2.username = "wacow"
resources.multidb.db2.password = "123456"
resources.multidb.db2.dbname   = "wacow"
resources.multidb.db2.charset  = "UTF8"
resources.multidb.db2.params.profiler.enabled = true
resources.multidb.db2.params.profiler.class = "Zend_Db_Profiler_Firebug"
;resources.multidb.db2.default = true
 
[staging : production]
 
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
 
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1

不同以往 要起始ZFDebug只要加入

autoloadernamespaces[] = "ZFDebug"

並在DB加入 Zend_Db_Profiler_Firebug設定

<?php
 
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected $_defaultDb = null;
	protected function _initDatabase() {
		if ($this->_defaultDb === null) {
		if ($this->hasPluginResource('multidb')) {
			$this->bootstrap('multidb');
			$resource = $this->getPluginResource('multidb');
			$this->_defaultDb = $resource->getDefaultDb();
		}elseif($this->hasPluginResource('db')){
			$this->bootstrap('db');
			$this->_defaultDb = $this->getPluginResource('db')->getDbAdapter();
		}}
	}
	protected function _initZFDebug() {
		$options = array(
	    	'plugins' => array(
	    	'Html',
				'Variables',
				'File' => array('base_path' => realpath(APPLICATION_PATH . '/../')),
				'Memory',
				'Time',
				'Registry',
				'Exception',
	 	));
		if ($this->_defaultDb === null) {
            $this->_initDatabase();
        }
		$options['plugins']['Database']['adapter'] = $this->_defaultDb;
		$debug = new ZFDebug_Controller_Plugin_Debug($options);
 
		$this->bootstrap('frontController');
		$frontController = $this->getResource('frontController');
		$frontController->registerPlugin($debug);
	}
}

_initDatabase() 部份有實座分離單資料庫與多重資料庫的試驗.
其他尚在研究中……………….

Leave a Comment more...

FreeBSD NGINX + PHP5

by admin on 三月.30, 2010, under FreeBSD, PHP & MYSQL

先去官網找到freebsd專用的port

http://php-fpm.org/downloads/freebsd-port/

# fetch http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.13.diff.gz
# mv php-5.2.10-fpm-0.5.13.diff.gz /usr/ports/distfiles/
# fetch http://files.directadmin.com/services/custombuild/php-5.2.9-mail-header.patch
# mv php-5.2.9-mail-header.patch /usr/ports/distfiles/
# fetch http://php-fpm.org/downloads/freebsd-port/php-5.2.10-fpm-0.5.13.tar.gz
php-5.2.10-fpm-0.5.13.tar.gz                  100% of 9503  B   45 kBps
# tar zxvf php-5.2.10-fpm-0.5.13.tar.gz -C /usr/ports/lang
x php5-fpm/
x php5-fpm/files/
x php5-fpm/Makefile
x php5-fpm/distinfo
x php5-fpm/pkg-descr
x php5-fpm/pkg-plist
x php5-fpm/files/php-fpm.sh.in
x php5-fpm/files/patch-scripts::phpize.in
x php5-fpm/files/patch-TSRM_threads.m4
x php5-fpm/files/patch-Zend::zend.h
x php5-fpm/files/patch-Zend_zend_list.c
x php5-fpm/files/patch-Zend_zend_list.h
x php5-fpm/files/patch-ext_standard_array.c
x php5-fpm/files/patch-ext_standard_basic_functions.c
x php5-fpm/files/patch-ext_standard_dns.h
x php5-fpm/files/patch-ext_standard_image.c
x php5-fpm/files/patch-php.ini-dist
x php5-fpm/files/patch-php.ini-recommended
x php5-fpm/files/patch-main::php_config.h.in
x php5-fpm/files/patch-main_SAPI.c
x php5-fpm/files/patch-acinclude.m4
x php5-fpm/files/patch-configure.in
 
# cd /usr/ports/lang/php5-fpm/
# make install clean
# fetch http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
# mv nginx_upload_module-2.0.12.tar.gz /usr/ports/distfiles/
# fetch http://mod-zip.googlecode.com/files/mod_zip-1.1.5.tar.gz
# mv mod_zip-1.1.5.tar.gz /usr/ports/distfiles/
# cd /usr/ports/www/nginx-devel
# make install clean

編輯/usr/local/etc/php-fpm.conf
nobody改成www

Unix user of processes
nobody
Unix group of processes
nobody

編輯/usr/local/etc/nginx/nginx.conf

#user  nobody;
worker_processes  2;
 
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
#pid        logs/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
    #access_log  logs/access.log  main;
 
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
 
    sendfile        on;
    #tcp_nopush     on;
    server_tokens  off;
    tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;
 
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;
 
    gzip_static on;
    gzip  on;
    gzip_min_length  1k;
    gzip_proxied     expired no-cache no-store private auth;
    gzip_buffers 4 16k;
    gzip_comp_level   5;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_disable     "MSIE [1-6]\.";
    gzip_vary on;
 
    server {
        listen       80;
        server_name  localhost;
	autoindex  on;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   /www;
            index  index.php index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
 
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /www;
     	    fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
            deny  all;
        }
 
    }
  server {
    listen       80;
    server_name  test2.localhost www.test2.localhost;
    access_log  /var/log/test2.access.log;
    error_log  /var/log/test2.error.log;
    location ~* ^.+\.(jpg|jpeg|gif)$ {
     root   /www/test2/pub;
     expires 30d;
    }
    location ~* ^.+\.(js|css)$ {
     root   /www/test2/pub;
     expires 1h;
    }
    location / {
        root   /www/test2/pub;
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
      root           /www/test2/pub;
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME  /www/test2/pub$fastcgi_script_name;
      include        fastcgi_params;
    }
    location ~ /\.ht {
            deny  all;
    }
  }
 
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
 
    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
 
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
 
    #    ssl_session_timeout  5m;
 
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;
 
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

編輯/etc/rc.conf

php_fpm_enable="YES"
nginx_enable="YES"

http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

http://wiki.nginx.org/Main

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!