วิธีติดตั้ง XHProf

XHProf คืออะไร?

สั้นๆ คือมันเป็นเครื่องมือกลุ่ม Profiler หรือ Performance analysis ซึ่งไว้ใช้ตรวจสอบว่าโค้ด PHP ของเราทำงานช้าตรงไหน มันสามารถบอกได้ในระดับ Function หรือ Method โดยบอกได้ว่าถูกเรียกกี่ครั้ง ใครเป็นคนเรียก ใช้เวลาในการทำงานส่วนนั้นนานเท่าไร และสามารถออกเป็นกราฟเพื่อดูได้ง่ายขึ้น เป้าหมายคือใช้ดูว่าโค้ดส่วนไหนเขียนดีหรือไม่ดี ยังสามารถปรับ pattern ได้ไหม คุ้มไหมที่จะทำ อะไรที่มันช้า คุณสามารถใช้สิ่งนี้กับพวก Legacy code ได้ โดยไม่ต้องไปงมโข่งว่าอะไรที่ช้า

อ่านเพิ่มเติม

Auto restart faxgetty when modem crash

Hi everybody in our world. I hope you have good health. Today I will paste my simple php code that I used in company server. My server got some problem that I don’t know what is source of this problem. I use Hylafax with Avantfax. Both of them update lasted version on Ubuntu 10.10. I know only it’s about segfault. I found some log at /var/log/messages and I don’t know anymore.

/…

I found php script in some website but I use 2 modem. (1 external 1 internal) That php script didn’t work so I modified script. It’s very simple version. I don’t put any license to it so you can modify it freely.

/ee

<?php
/**
* Check if faxgetty runs and if not restart the service
* It's about segfault. /var/log/messages
*
* For two modem by EThaiZone.com
*/

$process='faxgetty'; //process
$command="ps -Al -cmd| grep ".$process; //command !!!

ob_start();
passthru($command); //execute command
$result=ob_get_contents();
ob_end_clean();

if(preg_match('#'.$process.'\r?\n.+'.$process.'#', $result))
{
	echo "No problem. Faxgetty run fine.\n"; //OK
}
else
{
	echo "Restart hylafax\n";
	exec("service hylafax restart");
}

?>

Save it and run it via cronjob. I recommend to run every seconds because it don’t cause load on cpu that should worry. In my cron I put this.

* * * * *   php -q /checkfaxgetty.php

I hope this’s useful to you.  /bye

Make Avantfax can auto login

Today I receive request to make avantfax can auto login when user open firefox. User and pass is saved in browser itself.

I test many codes and I found simple way to do it. Start from root of localhost folder. (In my case is “/var/www/”) You must edit this file.

/avantfax/includes/templates/main_theme/templates/index.tpl

open file and find </script> and insert this code before it.

{if not $error}
    setTimeout('document.forms[0].submit()',500);
{/if}

This way you can make it auto login in first try and when user to pass isn’t correct. It won’t auto login again.

PS. I’m Thai so my english isn’t that good.  /= =a