Handy Command
perl -p -i -e ‘s/usr\/local\/apache/var\/www/g’ * (in a folder) find ./ -type f -exec sed -i ‘s/usr\/local\/apache/var\/www/g’ {} \; find ./ -type f -exec sed -i ‘s/fav_sku=`$fp_prdct.sku` fav_style=`$fp_prdct.is_styl`/fav_sku=“`$fp_prdct.sku`” fav_style=“`$fp_prdct.is_styl`”/’ {} \;
Continue Reading »Install PHPUnit On Debian
First my Debian version is: [root@www:~]# cat /proc/version Linux version 2.6.32-pony6-3 (root@debian) (gcc version 4.4.6 (Debian 4.4.6-14) ) #1 SMP Tue Mar 13 07:31:44 PDT 2012 Per PHPUnit To install PHPUnit, using the following two command: pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit However, nothing is simple, you may see the error message, like [root@www:~]# pear install pear.phpunit.de/PHPUnit Did not download optional dependencies: phpunit/PHP_Invoker, use –alldeps to download automatically phpunit/PHPUnit requires PEAR Installer (version >= [...]
Continue Reading »PHPMyAdmin connect to both Local and Remote Server
Add servers into config.inc.php, there may be two config.inc.php, one is under “/etc/phpmyadmin”, the other is under your web root folder. If so, update the one under your root. $i=0; $i++; //server 1 – local $cfg['Servers'][$i]['auth_type'] = ‘cookie’; $cfg['Servers'][$i]['verbose'] = ‘local’; $cfg['Servers'][$i]['host'] = ‘localhost’;//or ip:’10.9.8.1′ $cfg['Servers'][$i]['extension'] = ‘mysqli’; //server 2 – remote $i++; $cfg['Servers'][$i]['auth_type'] = ‘cookie’; $cfg['Servers'][$i]['verbose'] = ‘remote’; $cfg['Servers'][$i]['host'] = ‘remote.com’;//hostname or ip:’10.9.8.1′ // this server must allow remote clients, e.g., host 10.9.8.% // [...]
Continue Reading »Reading Note 4 – PHP 5 Advanced OOP and Design Patterns
OK. It’s Object Oriented Time! 1. Because a constructor cannot return a value, the most common practice for raising an error from within the constructor is by throwing an exception. 2. $obj = NULL will destruct the obj (or __desctruct() ill be called. 3. Static properties are defined by using static keywords, and you can think it as global variable that sit inside the class, but are accessible from anywhere via the class. Static property [...]
Continue Reading »Reading Note 3 – PHP 5 Advanced OOP and Design Patterns
Basic but you may not know php syntax 1. use variable as variable name $file1 = “hello”; $file2 = “world”; $file3 = “php”; for($i=1; $i 28, “Barbara” => 67); //reset($ages); //reset if needed $person = each($ages); print_r($person); /* Array ( [1] => 28 [value] => 28 [0] => John [key] => John ) */ list($name,$age) = each($ages); echo $name . “: ” . $age . “\n”; //You got: Barbara: 67. Because you did not use [...]
Continue Reading »Reading Note 2 – PHP 5 Advanced OOP and Design Patterns
Problem of Object Orient in PHP4. pass an object to a variable, a copy of the object would be created unless you pass it by reference (&) prevented implementing some additional features on top of the existing object model, such as public/private/protected, unified constructor/destructor name, interfaces, instanceof (instead of is_a() in PHP4), final methods/classes, __clones, class constants, static methods/members, abstract classes/methods, class type hints in function declarations, iterators, __autoload() New features in PH5 Error handling foreach [...]
Continue Reading »Reading Note 1 – PHP 5 Advanced OOP and Design Patterns
Main Different between PHP3 and PHP4 While PHP 3 still continuously parsed the scripts while executing them, PHP 4 came with a new paradigm of “compile first, execute later.” The compilation step does not compile PHP scripts into machine code; it instead compiles them into byte code, which is then executed by the Zend Engine, the new heart of PHP 4. PHP 4.1.0, introduced superglobals such as $_GET and $_POST. Superglobals can be accessed from [...]
Continue Reading »Work with Litle PHP SDK
In a recent project, we need to process Credit Card on real time. The vendor we use is Litle. Litle provides some SDK libraries including PHP, JAVA, .NET, RUBY, and PYTHON, but lack of documentation. They host the code in Github, and we grab the php SDK from there. After download the source code, you can run Setup script (under litle-sdk-for-php-master/lib/). During the setup, you can choose Litle URL including different environments. For playing, you [...]
Continue Reading »Run PHP in command line in Netbeans
PHP is a web programming language, but sometimes you may want to run PHP as script (in the command line,) in the other words not showing the results in browser. You can actually do this in Windows environment with Netbeans. Here is how, 1. Grab an PHP interpreter – The easiest way is to download WAMP server 2. Define PHP interpreter for NetBeans – Go to Tools > Options > PHP, and then set up [...]
Continue Reading »Nginx Log Rotation
One of my site is running on Nginx server, and the logs (access log and error log) is getting large very quick . I don’t want to turn it off, because sometime I need to check them. Without using log rotation, I think it’s not good for performance because write into a large file (says 1G) could be slow (correct me if you don’t agree), and another big issue is that it takes long time [...]
Continue Reading »








