跳到主要內容

發表文章

使用phpize

什麼是phpize?phpize是用來加入php擴充模組。 如果想在已經編譯好的php加入擴充模組,則可以使用phpize。 以下以安裝 phpredis 為範例 # 先進入到phpredis資料夾 cd phpredis # 會發現資料夾裡有個*.m4, 在執行phpize時必須要有的檔案 phpize # 會出現以下資訊 Configuring for: PHP Api Version: 20100412 Zend Module Api No: 20100525 Zend Extension Api No: 220100525 # 執行此資料夾的configure,是用來產生編譯時需要的Makefile檔案 ./configure # 接著就開始編譯並安裝 make make install 安裝後要記得在php.ini上加入extension=redis.so phpize詳細資訊到 php.net 查看

安裝composer

Composer ,其實就是作曲家(咦?!那跟php有什麼關係...。),請忽略剛剛(消音-嗶) Composer其實是個依賴管理的工具,簡言之就是,說明目前這個專案需要用到哪些套件或函式庫。所以設定需要的套件或函式庫後,執行composer會產生一個目錄(例如vendor)存放你在設定上的那些套件。 設定範例,產生一個composer.json加入zendframework { "require" : { "zendframework/zendframework" : "2.2.*" } } 那麼要如何安裝呢?首先當然得先有composer,所以我們先去下載composer 在Linux底下 curl - sS https :// getcomposer . org / installer | php 這樣就可以在當前目錄下取得composer.phar檔案 如何使用呢? # 可以看到指令列表 php composer.phar list # 或是直接執行 ./composer.phar list # 建立了composer.json,必須先進行install ./composer.phar install # 更新套件 ./composer.phar update # 顯示已加入的套件 ./composer.phar show -i 上面都是加入別人的套件,以下就來談談如何建立自己的套件。 # 在套件資料夾下執行 ./composer.phar init # 接著就會產生一連串的問題要求你輸入 Package name (<vendor>/<name>) [chuehnone/test]: Description []: Author: Minimum Stability []: License []: Define your dependencies. Would you like to define your dependencies (require) interactiv...

面試前的筆試-實作題-費氏數列

費氏數列,是F1 = F2 = 1, Fn = Fn-1+Fn-2,給以下兩個範例,請實做出程式。 func(1) = 1 func(3) = 1 2 3 5 8 <?php echo func( 1 ); echo func( 3 ); function f ( $x ){ if ( $x == 1 || $x == 2 ) return 1 ; return f( $x - 1 ) + f( $x - 2 ); } function func ( $x ){ $ans = '' ; $len = $x * 2 - 1 ; for ( $i = 1 ; $i <= $len ; $i ++ ) $ans .= f( $i + 1 ) . ' ' ; return $ans ; } ?> 今天應該是太緊張了...,看到這題我無法理解為什麼func(3) = 1 2 3 5 8,但回到房間在想起這件事情,原來是要我推理出可能的func,就馬上寫出來了。 好吧,看來今天的面試結果應該是無望了XD

MySQL INSERT or UPDATE

有些時候在記錄資料時,總是會需要判斷資料有無存在,在進行資料寫入,或是更新資料。 所以至少都得先進行SELECT再去判斷資料有無存在,不存在就INSERT,存在就進行UPDATE,之前從沒找過有沒有更簡單的方法進行。 這次無意間找資料時,才看到INSERT ... ON DUPLICATE KEY UPDATE ...。 舉個簡單的範例,現在有個TABLE A如下 SQL範例如下 INSERT INTO ` A ` ( ` item_id ` , ` item_count ` , ` count_date ` ) VALUES ( 'SwefcskoWdsl' , 1 , '2013-05-14' ) ON DUPLICATE KEY UPDATE ` item_count ` = ` item_count ` + 1 ; 這段SQL就會依照當item_id與count_date資料不存在,則會新增;否則就會在指定的item_id與count_date的item_count進行+1的動作。 MySQL文件 P.S. 這時發現以前的自己好蠢Orz...

Apache Http Header

安裝了Apache後,總是要注意安全設定,而每次重灌後,總是容易忘東忘西...,所以就把一些基礎的筆記紀錄一下。 這次要設定的是標頭( Header )資訊,為了不讓別人知道自己伺服器資訊,至少要把 Header 中與伺服器相關的資訊關閉或是不顯示詳細資訊。 要如何知道自己傳送出去的 Header 呢? 以下用php簡單寫了一個範例程式 <?php //要測試的網址 $url = 'www.google.com' ; $timeout = 5 ; $ch = curl_init (); curl_setopt ( $ch , CURLOPT_URL, $url ); curl_setopt ( $ch , CURLOPT_HEADER, true ); curl_setopt ( $ch , CURLOPT_NOBODY , true ); curl_setopt ( $ch , CURLOPT_TIMEOUT, $timeout ); $header = curl_exec ( $ch ); curl_close ( $ch ); echo $header ; ?> 這樣就可以取得header資訊 :P。( curl_setopt詳細內容 ) 如果不想寫程式,當然有現成的工具可測試。 http://www.webconfs.com/http-header-check.php 一般預設的顯示資料如下(以目前使用的伺服器為範例) Date: Fri, 22 Feb 2013 12 : 15 : 03 GMT Server: Apache/ 2.2 . 15 (CentOS) Location: index.v Content-Length: 0 Content- Type : text/html; charset=UTF- 8 設定完Apache設定檔後顯示的資料如下。 Date: Fri, 22 Feb 2013 12 : 17 : 29 GMT Server: Apache Location: index.v Content-Length: 0 Content- Type...

[FFmpeg] CentOS安裝FFmpeg

在使用之前 FFmpeg 之前,要先進行安裝。 yum install ffmpeg ffmpeg-devel 因為Server是用 CentOS ,所以預設套件並不存在,而有個快速的方法就是新增Dag套件庫,在 /etc/yum.repos.d/ 新增  dag.repo  檔案,此檔案內容如下 [ dag ] name = Dag RPM Repository for Red Hat Enterprise Linux baseurl = http://apt.sw.be/redhat/el $releasever /en/ $basearch /dag gpgcheck = 1 enabled = 1 設定完後,在執行一次安裝,卻發現沒有 GPG 公開金鑰,這時還要進行安裝 RPMforage 套件庫。 rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm 這時應該都能順利安裝了。(詳細資訊可參考: How to Install FFmpeg in Linux ~The Easy Way~ ) 其他資訊: FFmpeg指令集

使用jQuery的Plugin管理cookie

為了能在javascript上管理cookie,因此採用了jQuery的Plugin: jQuery.Cookie 如何使用呢? 上面的連結是連到github,可以看到有個README.md檔案,裡面有說明如何使用。 以下是範例內容 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 //Create session cookie: $.cookie( 'the_cookie' , 'the_value' ); //Create expiring cookie, 7 days from then: $.cookie( 'the_cookie' , 'the_value' , { expires: 7 }); //Create expiring cookie, valid across entire site: $.cookie( 'the_cookie' , 'the_value' , { expires: 7 , path: '/' }); //Read cookie: $.cookie( 'the_cookie' ); // => "the_value" $.cookie( 'not_existing' ); // => null //Delete cookie: // Returns true when cookie was found, false when no cookie was found... $.removeCookie( 'the_cookie' ); // Same path as when the cookie was written... $.removeCookie( 'the_cookie' , { path: '/' }); 這時候就可用PHP印出cookie,確認是否有成功。 1 2 3 <?php var_dump ( $_COOKIE ...