Best Encode for PHP5 and support symfony
by kary on May.23, 2010, under Linux, Symfony
In symfony, encoded classes excluded from config_autoload_yml.php. Because when symfony found the classes and read the contents, symfony can not find the words that contain abstract class|interface, final class|interface, class.
Following is the solution to make it work.
1. create config_handlers.yml in sf_root_dir/config folder and add
config/autoload.yml: class: myAutoloadConfigHandler
2. add myAutoloadConfigHandler.class.php to sf_root_dir/config
class myAutoloadConfigHandler extends sfAutoloadConfigHandler
{
static public function parseFile($path, $file, $prefix)
{
$mapping = array();
$content = file_get_contents($file);
preg_match_all('~^\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi', $content, $classes);
if (count($classes[1]) == 0)
{
if (stristr($content, 'ioncube_loader') !== FALSE)
{
preg_match_all('~^//\s*(?:abstract\s+|final\s+)?(?:class|interface)\s+(\w+)~mi',
$content, $classes);
}
}
foreach ($classes[1] as $class)
{
$localPrefix = '';
if ($prefix)
{
// FIXME: does not work for plugins installed with a symlink
preg_match('~^'.str_replace('\*', '(.+?)', preg_quote(str_replace('/', DIRECTORY_SEPARATOR, $path), '~')).'~', str_replace('/', DIRECTORY_SEPARATOR, $file), $match);
if (isset($match[$prefix]))
{
$localPrefix = $match[$prefix].'/';
}
}
$mapping[$localPrefix.strtolower($class)] = $file;
}
return $mapping;
}
}
3. change ProjectConfiguration.class.php and add myAutoloadConfigHandler.class.php
public function setup()
{
require_once(sfConfig::get('sf_root_dir').'/config/myAutoloadConfigHandler.class.php');
4. using ionCude Encoder to encode the files and add comment “class sfClassName” to the encode file.
Example: myTools.class.php
// IONCUBE ENCODER 6.5 EVALUATION
// THIS LICENSE MESSAGE IS ONLY ADDED BY THE EVALUATION ENCODER AND
// IS NOT PRESENT IN PRODUCTION ENCODED FILES
// class myTools
if(!extension_loaded(’ionCube Loader’)){$__oc=strtolower(substr(php_uname(),0,3));$__ln=’ioncube_loader_’.$__oc.’_’.substr(phpversion(),0,3).(($__oc==’win’)?’.dll’:’.so’);@dl($__ln);if(function_exists(’_il_exec’)){return _il_exec();}$__ln=’/ioncube/’.$__ln;$__oid=$__id=realpath(ini_get(’extension_dir’));$__here=dirname(__FILE__);if(strlen($__id)>1&&$__id[1]==’:'){$__id=str_replace(’\\’,'/’,substr($__id,2));$__here=str_replace(’\\’,'/’,substr($__here,2));}$__rd=str_repeat(’/..’,substr_count($__id,’/')).$__here.’/';$__i=strlen($__rd);while($__i–){if($__rd[$__i]==’/'){$__lp=substr($__rd,0,$__i).$__ln;if(file_exists($__oid.$__lp)){$__ln=$__lp;break;}}}@dl($__ln);}else{die(’The file ‘.__FILE__.” is corrupted.\n”);}if(function_exists(’_il_exec’)){return _il_exec();}echo(’Site error: the file ‘.__FILE__.’ requires the ionCube PHP Loader ‘.basename($__ln).’ to be installed by the site administrator.’);exit(199);
?>
4+oV5Djj/RjxxiMy5hHec2J9iSWGrP53JymQThUitFyI+rDD9TZc2z8BXRg+rQoi2zlgyd1jv271
LGLiuMCfZM9Wyo97ZTp208rr6ekINq15uTrYKONgK8dPivUR3GzHKXjbKRNv+toLg2bgkSIlKTzC
3KaXVdeReVGarLrmVxaC7L3pJ4Lt1Nex/HVwg3foRqvLGrv0vowUiL1k4uv87wuEJhST20s/KQ6M
8JwWXKksGBPbJ3cDMQuODDnHqNo//6G0VT4kAb4NP/LU9ejObXbOZx25YnWCgS1kyeeANpe++7Tv
rGwE4smPZpXuQawA5zZR2esxUiftfJXP4Pc0QmUUJRwcQhf2brOmWtb9JchulRNIRLgUxzmcYXk3
2z4KuvH3XkH/r2MnNXwiL1T172aBUF65ScDqVF3gZqJX1sOqvDwfqcVOPTA7PV1WUcGFbM58y0Cs
5. Now your files will be able auto load by the symfony.
6. Some link for ionCube
* The ionCube Home page
ioncube.com
* The Standalone Encoder
ionCube Standalone PHP Encoder
* The online Encoder
ionCube Online PHP Encoder
7. Finally, I have write a task to encode the files, if you need the task file, please send a email to me. I will send the file to you.
Symfony 1.2 APC Cache
by kary on May.14, 2010, under Uncategorized
;##### APC config ###
;apc.enabled = On
apc.enable_cli = On
apc.shm_size = 128
Doctrine cache
As of sf 1.4
http://www.symfony-project.org/advent_calendar/12/en
http://www.doctrine-project.org/documentation/manual2/1_0/en/one-page#caching
http://www.sfblog.fr/page/utiliser-memcache-avec-doctrine-sous-symfony
Setup for sf 1.2
In the ProjectConfiguration:
-
public function initialize() { //enable Doctrine cache $manager = Doctrine_Manager::getInstance(); $cacheDriver = new Doctrine_Cache_Apc(); $manager->setAttribute(Doctrine::ATTR_RESULT_CACHE, $cacheDriver); }
Example query (in UllFlowAppTable.class.php):
-
/** * Find by Id * * @param integer $id * @return Doctrine_Record */ public static function findById($id) { $q = new Doctrine_Query; $q ->from('UllFlowApp') ->where('id = ?', $id) ->useResultCache(true) ; return $q->execute()->getFirst(); }
Compile apc and ssh2 for PHP 5.2.xx in Linux (ssh2, apc)
by kary on May.14, 2010, under Linux
APC for Php 5.2.xx:
- wget http://pecl.php.net/package/apc
- unzip the download file
- run phpize in the unzip folder
- ./configure –enable-apc –with-php-config=/usr/local/bin/php-config
- make && make install
- enable the apc.so in php.ini
SSH2 for Php 5.2.xx
- wget http://www.libssh2.org/download/libssh2-1.2.5.tar.gz
- wget http://pecl.php.net/get/ssh2
- unzip all downloaded files
- in libssh2 folder
- ./configure && make && make install
- in SSH2 folder
- phpize
- ./configure && make && make install
- enable the ssh2.so in php.ini
Update Boost in CentOS 5 x86_64
by kary on May.10, 2010, under Linux
yum install libicu-devel
yum install libicu
yum install icu
export ICU_PATH=/usr
export ICU_LINK=-L/usr/lib64
export EXPAT_INCLUDE=/usr/include
export EXPAT_LIBPATH=/usr/lib64
yum install openmpi-devel
yum install expat-devel
./bootstrap.sh --prefix=/usr
Edit project-config.jam
add
using mpi;
./bjam install
Google translation API
by kary on May.06, 2010, under HTML
http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=%E5%BB%A3%E5%B7%9E&langpair=zh-TW|en
by kary on Mar.05, 2010, under HTML
Different CSS for IE6、IE7、IE8、Firefox
symbol:「\9」、「*」、「_」
#tip {
background:blue; /*Firefox background to blue*/
background:red \9; /*IE8 red*/
*background:black; /*IE7 black*/
_background:orange; /*IE6 orange*/
}
Install Windows 7 From USB Disk
by kary on Mar.01, 2010, under Windows
Requirement:
- USB Disk (Min 4 GB)
- Windows 7 Source
- MBRwiz (download here)
Process:
- Format USB disk with NTFS format.
- Open command prompt (”cmd”)
- go to MDRwiz folder and type below command
mbrwiz /list (note down disk number of your USB disk)
mbrwiz /disk=X /active=1 (X is Number of your USB disk) - go to “windows 7 source folder/boot”
- bootsect /nt60 X: /mbr (X is the drive of your USB disk )
- copy all windows 7 soruce to your USB disk
- Your windows 7 should be able install from the USB disk.
Load balance in CentOS
by kary on Sep.02, 2009, under Linux
1. Testing your system if the bonding driver is available
modprobe bonding miimon=100
ifconfig bond0 192.168.1.1 netmask 255.255.255.0
ifconfig eth0 down
ifconfig eth1 down
ifenslave bond0 eth0 eth1
2. Create the network configration file for next reboot
create /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
NETWORK=192.168.1.0
NETMASk=255.255.255.0
IPADDR=192.168.1.13
GATEWAY=192.168.1.1
USERCTL=no
edit /etc/sysconfig/network-scripts/ifcfg-eth0 and eth1
**** original config *****
MASTER=bond0
SLAVE=yes
load bonding driver to modprode
edit /etc/modprobe.conf add
****** original config ********
alias bond0 bonding
options bond0 miimon=100 mode=1
reboot system
Format USB for Linux (Ext3)
by kary on Sep.02, 2009, under Linux
Leave a Comment :ext3, format, Linux, usb disk more...