Posted by admin | Posted in PHP, SEO網站優化 | Posted on 04-03-2010
0
function is_bot(){
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$botchar = 『/(baidu|google|spider|soso|yahoo|sohu-search|yodao|robozilla)/i』;
if(preg_match($botchar, $ua)) {
return true;
}else{
return false;
}
}
if(is_bot()){
header(’Location:http://blog.mm520.net);
}else{
header(’Location:http://www.google.com.tw’);
}
Posted by admin | Posted in PHP | Posted on 04-03-2010
0
前一陣子在測試 msn 發送訊息時,網頁會停留很久
後來想到一個方法
就是用PHP 背景執行
需要花費大量的時間處理時,放到背景執行給他自己去Run 就對了..
像處理圖片,影片轉檔等等!
參考資料
Linux:
shell_exec( ‘/usr/local/bin/php /tmp/SEO.php &’ );
shell_exec( ‘/usr/local/bin/php /tmp/SEO.php > /tmp/cmd_out &’ );
/usr/local/bin/php /tmp/SEO.php > /tmp/cmd_out &`
Windows:
pclose(popen(』start /B C:\php\php.exe > C:\temp\out』, 『r』) );
Executing background processes from PHP on Windows』
$cmd = 'C:\php\php.exe C:\SEO.php' ;
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run(』cmd /C $cmd』, 0, false);
?>
ignore_user_abort(); // run script in background 背景跑.
set_time_limt(0); // run script forever 程式執行時間不做限制.
$interval=60*15; // do every 15 minutes… 15分鍾
do{
// add the script that has to be ran every 15 minutes here 每15分鍾執行一次.
sleep($interval); // wait 15 minutes 等待15分鍾
}while(true);