Tag Archives: php

PHP 5.4 與 php-test-helpers

先給連結,PHP 5.4 可以編的版本在這裡:github.com/gslin/php-test-helpers,clone 下來後的安裝方法是: phpize ./configure make make install 另外自己增加 extensions.ini: extension=test_helpers.so 主要是 PHP 內部的資料結構有變動,本來存取的方式要改掉。發了 pull request 但不知道作者會不會收,如果有需要的人可以自己先裝。 會用到 php-test-helpers 是因為寫 test case 的時候要換掉整個 HttpRequest,而 RunKit 不能換系統的 HttpRequest,所以找了不少 extension 發現 php-test-helpers 可以用。 換法是這樣: set_new_overload(function($name){ if (‘HttpRequest’ == $name) { return … Continue reading

Posted in Computer, Murmuring, Programming, Software | Tagged , , , | Leave a comment

PHP 5.4

PHP 5.4 前幾天正式釋出了:「PHP 5.4.0 released!」,新增與改變了很多東西。 有些蠻值得注意的地方: safe mode 與 magic quote 都消失了,升級後需要重新檢查 php.ini。 array_combine(array(), array()) 不再傳回 FALSE 了,總算是傳回 array()。 可以用 [] 表示 array() 了。 function 傳回 array 後可以直接對 array 取值,也就是 foo()[0] 變合法語法了。 new 完後可以直接 call function 了,也就是 (new Foo)->bar() 變合法語法了。 … Continue reading

Posted in Computer, Murmuring, Programming, Software | Tagged , , | Leave a comment

PHP 提供的資料結構…

從「How big are PHP arrays (and values) really? (Hint: BIG!)」這篇看到的。文章本身值得花些時間看過了解,不過對我來說重點在最後面的 SplFixedArray。 PHP 的 Datastructures 說明目前 PHP SPL 所支援的 data structure,在記憶體用量以及效率上面都會比自己實作來的小且快。 可以看到很多都支援 Countable、Iterator,以及 ArrayAccess,代表可以用 foreach() 或是對應的方式存取… 如果自己寫 library 的時候應該要善用這些 SPL。

Posted in Computer, Murmuring, Programming, Software | Tagged , , , , | Leave a comment

把 blog 搬回自己主機…

把 blog 搬回自己的主機上跑,好像沒有快多少…

Posted in Blog, Computer, Murmuring, Network, WWW | Tagged , , | 1 Comment

PHP 5.3 的 anonymous function

在看到 PHPConf Taiwan 2011 的議程介紹後,看到有人在推薦 Slim Framework,一連上去就看到包含 anonymous function 的 sample code: <?php require ‘Slim/Slim.php’; $app = new Slim(); $app->get(‘/hello/:name’, function ($name) { echo “Hello, $name!”; }); $app->run(); ?> 然後回頭去翻 PHP 的說明:「Anonymous functions」,發現是從 PHP 5.3 開始支援。 於是在 JavaScript 上常用到的技巧就也可以在 PHP … Continue reading

Posted in Computer, Murmuring, Network, Programming, WWW | Tagged , , , | 2 Comments

Heroku 上跑 PHP 的心得與感想…

Heroku 不愧是 PaaS 中的領先品牌,deploy 的操作及穩定性都相當好,加上 Heroku 每個 project 都有 1 free dyno 可以使用,對於 prototyping 其實相當棒… 關於要怎麼在 Heroku 上跑 PHP,可以參考 xdite 寫的「Create PHP application on Heroku without Facebook account」這篇文章。 有幾個要抱怨的: PHP 是用 Apache HTTP Server 跑的,所以可以用 .htaccess 寫 rewrite rule,不過 Options … Continue reading

Posted in Cloud, Computer, Murmuring, Network, Programming, WWW | Tagged , , , , , , | Leave a comment

PHP 長期計畫:廢除 ext/mysql,改用 pdo_mysql 或 mysqli

在 Hacker News 上看到的長期計畫,要廢除 ext/mysql:「deprecating ext/mysql」。 主要的原因是 security 習慣問題。因為 ext/mysql 不支援 prepare 與 execute 這類不需要自己處理 escape 的函式,所以使用 ext/mysql 的人必須自己處理 escape 的問題,也就是透過 mysql_escape_string 或是 mysql_real_escape_string。而很多書籍為了讓初學者容易了解,會給出很糟的範例,像是: mysql_query(“SELECT * FROM `user` WHERE `username` = ‘$username’;”); 而 $username 沒有先檢查過。 依照提議,目前只會在文件上建議改用 PDO 或是 mysqli,不會對目前版本有任何改變。接下來是 5.5 … Continue reading

Posted in Computer, Murmuring, Programming, Security, Software | Tagged , , , , , , | 1 Comment

mod_fcgid 與 PHP

先不論效能之類的問題,mod_fcgid 跑 PHP 的設定比 mod_fastcgi 簡單許多。(參考之前寫的「apache22 (worker) + mod_fastcgi + php5-fcgi」這篇文章) 首先是把 module load 進來: LoadModule fcgid_module libexec/apache22/mod_fcgid.so 再來是把副檔名加上去,以及告知什麼副檔名要用什麼程式包: AddHandler fcgid-script .php FcgidWrapper /usr/local/bin/php-cgi .php 就這樣而已… 預設會跑一隻 php-cgi,需要的時候會再多拉幾隻。以他的方式看起來 code segment 不會共用,這種設定方式給小站台用還可以… 接下來看看有沒有辦法在 .htaccess 內直接吃本地的 FastCGI process…

Posted in Computer, Murmuring, Network, Software, WWW | Tagged , , , | Leave a comment

PHP 的 Heroku

在「PHP Fog Raises $1.8 Million To Be The Heroku Of PHP」裡面提到兩家:PHP Fog 與 cloudControl。 兩者都是以 PHP 為底層語言基礎的平台。其中 PHP Fog 還沒開張,而 cloudControl 已經開張了,以歐洲的 EC2 為底層。 不過 cloudControl 選用 Bazaar 為版本管理系統,這點不知道是什麼考量… (PHP 是用 Subversion)

Posted in Cloud, Computer, Murmuring, Network, Programming, WWW | Tagged , , | 1 Comment

用 Plack 提供的 CGI 跑 Adminer…

在「用 Plack 跑 CGI」提到用 Plack 跑 CGI,目的是把 PHP 寫的 Adminer (一個取代 phpMyAdmin 的工具) 跑起來。 文章裡提到 PHP 沒辦法以 CGI mode 執行,主要有兩個原因。一個是 PHP 本身有安全機制,php-cgi 必須在有 REDIRECT_STATUS 這個環境變數下才能執行,另外一個是 php-cgi 需要用到 SCRIPT_FILENAME 這個非 CGI/1.1 標準 (RFC 3875 – The Common Gateway Interface (CGI) Version … Continue reading

Posted in Computer, Database, Murmuring, MySQL, Network, Programming, Software, WWW | Tagged , , , , , | Leave a comment