ไม่รู้ไปทำบุญที่ไหนมา ได้ใช้ Zend Studio version 7.0 พร้อม support ฟรีอีก 36 เดือน (3 ปี) ราคา Zend Studio - 3 years of upgrade and support ก็ $ 717.00 ครับ
อาจจะเพราะผมไปร่วมด้วยช่วยกันทดสอบ Zend Web Application Server ที่ชื่อ “Zenith” เมื่อกลางปีที่แล้วก็ได้มั้ง ก่อนที่จะออกมาเป็น Zend Server ตัวล่าสุดนี้ (มี Version CE ด้วยนะ ไปลองโหลดมาใช้ดู ลองแล้วปรับแต่งและรวดเร็วใช้ได้เลย)

Thai Share This
เอามาจาก 50+ PHP optimisation tips revisited ขอโน็ตไว้แล้วกัน กลัวหาย
- echo is faster than print. [Citation]
- Wrap your string in single quotes (’) instead of double quotes (”) is faster because PHP searches for variables inside “…” and not in ‘…’, use this when you’re not using variables you need evaluating in your string. [Citation]
- Use sprintf instead of variables contained in double quotes, it’s about 10x faster. [Citation]
- Use echo’s multiple parameters (or stacked) instead of string concatenation. [Citation]
- Use pre-calculations, set the maximum value for your for-loops before and not in the loop. ie: for ($x=0; $x < count($array); $x), this calls the count() function each time, use $max=count($array) instead before the for-loop starts. [Citation]
- Unset or null your variables to free memory, especially large arrays. [Citation]
- Avoid magic like __get, __set, __autoload. [Citation]
- Use require() instead of require_once() where possible. [Citation]
- Use full paths in includes and requires, less time spent on resolving the OS paths. [Citation]
- require() and include() are identical in every way except require halts if the file is missing. Performance wise there is very little difference. [Citation]
- Since PHP5, the time of when the script started executing can be found in $_SERVER[’REQUEST_TIME’], use this instead of time() or microtime(). [Citation]
- PCRE regex is quicker than EREG, but always see if you can use quicker native functions such as strncasecmp, strpbrk and stripos instead. [Citation]
- When parsing with XML in PHP try xml2array, which makes use of the PHP XML functions, for HTML you can try PHP’s DOM document or DOM XML in PHP4. [Citation]
- str_replace is faster than preg_replace, str_replace is best overall, however strtr is sometimes quicker with larger strings. Using array() inside str_replace is usually quicker than multiple str_replace. [Citation]
- “else if” statements are faster than select statements aka case/switch. [Citation]
- Error suppression with @ is very slow. [Citation]
- To reduce bandwidth usage turn on mod_deflate in Apache v2 [Citation] or for Apache v1 try mod_gzip. [Citation]
- Close your database connections when you’re done with them. [Citation]
- $row[’id’] is 7 times faster than $row[id], because if you don’t supply quotes it has to guess which index you meant, assuming you didn’t mean a constant. [Citation]
- Use <?php … ?> tags when declaring PHP as all other styles are depreciated, including short tags. [Citation]
- Use strict code, avoid suppressing errors, notices and warnings thus resulting in cleaner code and less overheads. Consider having error_reporting(E_ALL) always on. [Citation]
- PHP scripts are be served at 2-10 times slower by Apache httpd than a static page. Try to use static pages instead of server side scripts. [Citation]
- PHP scripts (unless cached) are compiled on the fly every time you call them. Install a PHP caching product (such as memcached or eAccelerator or Turck MMCache) to typically increase performance by 25-100% by removing compile times. You can even setup eAccelerator on cPanel using EasyApache3. [Citation]
- An alternative caching technique when you have pages that don’t change too frequently is to cache the HTML output of your PHP pages. Try Smarty or Cache Lite. [Citation]
- Use isset where possible in replace of strlen. (ie: if (strlen($foo) < 5) { echo “Foo is too short”; } vs. if (!isset($foo{5})) { echo “Foo is too short”; } ). [Citation]
- ++$i is faster than $ i++, so use pre-increment where possible. [Citation]
- Make use of the countless predefined functions of PHP, don’t attempt to build your own as the native ones will be far quicker; if you have very time and resource consuming functions, consider writing them as C extensions or modules. [Citation]
- Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview. [Citation]
- Document your code. [Citation]
- Learn the difference between good and bad code. [Citation]
- Stick to coding standards, it will make it easier for you to understand other people’s code and other people will be able to understand yours. [Citation]
- Separate code, content and presentation: keep your PHP code separate from your HTML. [Citation]
- Don’t bother using complex template systems such as Smarty, use the one that’s included in PHP already, see ob_get_contents and extract, and simply pull the data from your database. [Citation]
- Never trust variables coming from user land (such as from $_POST) use mysql_real_escape_string when using mysql, and htmlspecialchars when outputting as HTML. [Citation]
- For security reasons never have anything that could expose information about paths, extensions and configuration, such as display_errors or phpinfo() in your webroot. [Citation]
- Turn off register_globals (it’s disabled by default for a reason!). No script at production level should need this enabled as it is a security risk. Fix any scripts that require it on, and fix any scripts that require it off using unregister_globals(). Do this now, as it’s set to be removed in PHP6. [Citation]
- Avoid using plain text when storing and evaluating passwords to avoid exposure, instead use a hash, such as an md5 hash. [Citation]
- Use ip2long() and long2ip() to store IP addresses as integers instead of strings. [Citation]
- You can avoid reinventing the wheel by using the PEAR project, giving you existing code of a high standard. [Citation]
- When using header(’Location: ‘.$url); remember to follow it with a die(); as the script continues to run even though the location has changed or avoid using it all together where possible. [Citation]
- In OOP, if a method can be a static method, declare it static. Speed improvement is by a factor of 4. [Citation].
- Incrementing a local variable in an OOP method is the fastest. Nearly the same as calling a local variable in a function and incrementing a global variable is 2 times slow than a local variable. [Citation]
- Incrementing an object property (eg. $this->prop++) is 3 times slower than a local variable. [Citation]
- Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one. [Citation]
- Just declaring a global variable without using it in a function slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists. [Citation]
- Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance. [Citation]
- Methods in derived classes run faster than ones defined in the base class. [Citation]
- A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations. [Citation]
- Not everything has to be OOP, often it is just overhead, each method and object call consumes a lot of memory. [Citation]
- Never trust user data, escape your strings that you use in SQL queries using mysql_real_escape_string, instead of mysql_escape_string or addslashes. Also note that if magic_quotes_gpc is enabled you should use stripslashes first. [Citation]
- Avoid the PHP mail() function header injection issue. [Citation]
- Unset your database variables (the password at a minimum), you shouldn’t need it after you make the database connection.
- RTFM! PHP offers a fantastic manual, possibly one of the best out there, which makes it a very hands on language, providing working examples and talking in plain English. Please USE IT! [Citation]
Also see:
Thai Share This
ช่วงนี้แม้จะเซง หลาย ๆ เรื่องแต่ก็ต้องทำงาน ;P แต่ว่าเมื่อมีปัญหาเราก็ต้องแก้ไป วันนี้เลยเอามาโน๊ตไว้สักหน่อย
การลง Imagick เนี่ย บน Linux เนี่ยง่ายโคตร ๆ ยิ่งบน Ubuntu ยิ่งง่ายหนักไปอีก –_-‘ ประมาณว่า $ sudo apt-get แล้วก็นั่งรอ สักพักก็ได้แล้ว
แต่ถ้าเป็นบน Windows เนี่ย ตอน PHP 4 ถ้าให้ง่ายที่สุดก็คือ php_imagick.dll มาลง แต่บน PHP 5.2.+ มันไม่ง่ายแบบนั้น –_-‘ เพราะไฟล์ php_imagick มันไม่อยู่ใน PECL/Imagick สำหรับ Windows ให้โหลดได้ตามปรกติ (unofficial builds) ต้องหากันทั่ว Internet แต่พอเจอวิธีทำแล้วก็ต้องเอามาบันทึกไว้สักหน่อย
- โหลด ImageMagick-6.5.0-0-Q16-windows-dll.exe ที่ http://www.imagemagick.org/script/binary-releases.php#windows
- เสร็จแล้วไปโหลดตัว dynamic link (dll) ที่
The last build date: 09.07.2008
- Imagick 2.2.1-dev / PHP 5.2 / ImageMagick 6.4.1-Q8 / dynamic - php_imagick_dyn-Q8.dll
- Imagick 2.2.1-dev / PHP 5.2 / ImageMagick 6.4.1-Q16 / dynamic - php_imagick_dyn-Q16.dll
- Imagick 2.2.1-dev / PHP 5.2 / ImageMagick 6.4.1-Q8 / static - php_imagick_st-Q8.dll
- Imagick 2.2.1-dev / PHP 5.2 / ImageMagick 6.4.1-Q16 / static - php_imagick_st-Q16.dll
- โดยสำหรับผมโหลด php_imagick_dyn-Q16.dll มาแล้วเอาไปไว้ใน directory “ext” ของ PHP
- Rename ชื่อเป็น php_imagick.dll
- เสร็จแล้วเปิดไฟล์ php.ini แล้วเพิ่ม
extension=php_imagick.dll
- แล้วทำการ Restart ตัว Apache Services
- เขียนไฟล์ PHP สักตัวด้วย <?php phpinfo(); ?> แล้วก็ดูว่า imagick มันโหลดขึ้นมาหรือเปล่า (ถ้าทำถึงตรงนี้น่าจะเห็นแล้ว)
อ้างอิงข้อมูลบางส่วนจาก
http://valokuva.org/?page_id=50
Thai Share This
ตัว PHP-ExcelReader เป็น PHP Class ที่นำมาใช้อ่านไฟล์ Excel 97-2003 ได้ดีมากตัวนึง และแม้จะไม่ได้ update มาตั้งแต่ปี 2007 ก็ยังทำงานได้ดีบน PHP 5.2.8 ซึ่งบนระบบ Development Environment นั้นไม่มีปัญหา ซึ่งบนเครื่องผมเป็น Core 2 Duo ที่ทำงานบน Windows XP Pro 32bit ซึ่งทำงานได้ปรกติดี แต่แล้วพอเอาขึ้น Production Environment มันก็เกิดปัญหาขึ้นที่ function GetInt4d ซึ่งผมควานหาปัญหาและไล่ว่ามันเกิดจากตัว code เองหรือเปล่า หรือว่ามีปัญหากับ function พื้นฐานต่าง ๆ จาก Extension ของ PHP เองหรือเปล่า ซึ่งผมก็ว่าไม่ใช่ และพอเอาไปทำงานบน Production ตัวนึงที่เป็น 32bit CPU กลับไม่มีปัญหา ซึ่งลง Extension เหมือน ๆ กันด้วย –_-‘
แต่สุดท้ายผมก็ไล่ไปเจอสิ่งที่ผมคิดว่ามันเป็นเรื่องที่ทำให้ผม งง แต่มันก็เกิดขึ้นก็คือ [ 1487371 ] AMD64 dead loop fix สรุปง่าย ๆ ว่าเป็นปัญหาของ bitshift ใน OS 64bit ที่ bit ตัวแรกจะได้ค่าไม่ตรงกับใน OS 32bit ทำให้เกิดความผิดพลาด
ตัว error ที่พบคือ
CODE:
-
Notice: Uninitialized string offset: -138 in /home/www/public_html/excel/oleread.inc on line 27
-
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 71 bytes) in /home/www/public_html/excel/oleread.inc on line 133
ซึ่งแก้ไขได้ง่าย ๆ ด้วยการเปลี่ยนแปลง function GetInt4d ใหม่ตามด้านล่าง ก็สามารถทำงานบน OS 64bit ได้แล้ว
แก้ไขในไฟล์ oleread.inc
PHP:
-
function GetInt4d($data, $pos) {
-
// Hacked by Andreas Rehm 2006 to ensure correct result of the <<24 block on 32 and 64bit systems
-
$_or_24 =
ord($data[$pos+
3]);
-
if ($_or_24>=
128) $_ord_24 = -
abs((256-
$_or_24) <<
24);
-
else $_ord_24 = ($_or_24&127) <<24;
-
-
return ord($data[$pos]) |
(ord($data[$pos+
1]) <<
8) |
(ord($data[$pos+
2]) <<
16) |
$_ord_24;
-
}
Thai Share This