當前位置:文思屋>學習教育>考研>

筆試題(PHP工程師)

文思屋 人氣:1.5W

1. 請對POSIX風格和相容Perl風格兩種正則表示式的主要函式進行類比說明

筆試題(PHP工程師)

ereg preg_match

ereg_replace preg_replace

2. 請說明在中safe_mode開啟之後對於PHP系統函式的影響

3. PHP5中魔術方法函式有哪幾個,請舉例說明各自的用法

__sleep

__wakeup

__toString

__set_state

__construct,

__destruct

__call,

__get,

__set,

__isset,

__unset

__sleep,

__wakeup,

__toString,

__set_state,

__clone

__autoload

4. 請寫出讓,並說明如何在命令列下執行PHP指令碼(寫出兩種方式)同時向PHP指令碼傳遞引數?

5. PHP的垃圾收集機制是怎樣的

6.使物件可以像陣列一樣進行foreach迴圈,要求屬性必須是私有。

(Iterator模式的PHP5實現,寫一類實現Iterator介面)

7.請寫一段PHP程式碼,確保多個程序同時寫入同一個檔案成功

8. 用PHP實現一個雙向佇列

9. 使用正則表示式提取一段標識語言(html或xml)程式碼段中指定標籤的指定屬性值(需考慮屬性值對不規則的情況,如大小寫不敏感,屬性名值與等號間有空格等)。此處假設需提取test標籤的'attr屬性值,請自行構建包含該標籤的串

10.請使用socket相關函式(非curl)實現如下功能:構造一個post請求,傳送到指定http server的指定埠的指定請求路徑(如)。請求中包含以下變數:

使用者名稱(username):溫柔一刀

密碼(pwd):&123=321&321=123&

個人簡介(intro):Hello world!

且該http server需要以下cookie來進行簡單的使用者動作跟蹤:

cur_query:you&me

last_tm:…(上次請求的unix時間戳,定為當前請求時間前10分鐘)

cur_tm:…(當前請求的unix時間戳)

設定超時為10秒,發出請求後,將http server的響應內容輸出。複製內容到剪貼簿程式碼:Function encode($data, $sep = ‘&’){

while (list($k,$v) = each($data)) {

$encoded .= ($encoded ? “$sep” : “”);

$encoded .= rawurlencode($k).”=”rlencode($v);

}

Return $encoded;

}

Function post($url, $post, $cookie){

$url = parse_url($url);

$post = encode($data, ‘&’);

$cookie = encode($cookieArray, ‘;’);

$fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80, $errno, $errstr, 10);

if (!$fp) return “Failed to open socket to $url[host]“;

fputs($fp, sprintf(“POST %s%s%s HTTP/1.0n”, $url['path'], $url['query'] ? “?” : “”, $url['query']));

fputs($fp, “Host: $url[host]n”);

fputs($fp, “Content-type: application/x-www-form-urlencodedn”);

fputs($fp, “Content-length: ” . strlen($encoded) . “n”);

fputs($fp, “Cookie: $cookienn”);

fputs($fp, “Connection: closenn”);

fputs($fp, “$post n”);

while (!feof($fp)) {

echo fgets($fp, 128);

}

fclose($fp);

}

$url = ‘’;

$encoded = username=溫柔一刀& pwd=

$post = array(

‘username’=> ‘溫柔一刀’,

‘pwd => ‘&123=321&321=123&’,

‘intro => ‘Hello world!’

);

$cookie = array(

‘cur_query’ => ‘you&me,

‘last_tm’ => time() – 600,

‘cur_tm ‘=> time()

);

Post($url, $post, $cookie);

11.你用什麼方法檢查PHP指令碼的執行效率(通常是指令碼執行時間)和資料庫SQL的效率(通常是資料庫Query時間),並定位和分析指令碼執行和資料庫查詢的瓶頸所在?

1.指令碼執行時間,啟用xdebug,使用WinCacheGrind分析。

2.資料庫查詢,mysql使用EXPLAIN分析查詢,啟用slow query log記錄慢查詢。
PHP LAMP Engineer Test Paper

Question 1

What does print out?

A) 3

B) False

C) Null

D) 1

E) 0