PHP.ini Timezone

Posted on Thursday, May 27, 2010 in PHP

EST Example:
date.timezone = "America/New_York"

Installing APC and eAccelerator for PHP

Posted on Thursday, May 20, 2010 in Linux, PHP

Examples done on Ubuntu 9.04

Installing and Configuring APC:

#apt-get update
#apt-get install php5-dev
#apt-get install php-pear
#apt-get install apache2-threaded-dev
#apt-get install make
#pecl install APC

Add to php.ini:
extension=apc.so
may need to disable zend optimizer (or install as zend optimizer extension)
;zend_extension=/dir/ZendOptimizer.so
Usage:
apc_store("my_key",$obj,3600);
$cached_obj=apc_fetch("my_key");

Installing and Configuring eAccelerator
#cd /tmp/
#wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2
#tar xvjf eaccelerator-0.9.5.3.tar.bz2
#cd eaccelerator-0.9.5.3
#phpize
#./configure --with-eaccelerator-shared-memory
#make
#make install
#mkdir /var/cache/eaccelerator
#chmod 777 /var/cache/eaccelerator

add to php.ini:

;eAccelerator configuration
extension="eaccelerator.so"
eaccelerator.shm_size = "16"
eaccelerator.cache_dir = "/var/cache/eaccelerator"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.check_mtime = "1"
eaccelerator.debug = "0"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "0"
eaccelerator.shm_prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"

Usage:
eaccelerator_put("my_key",serialize($obj),3600);
$cached_obj=unserialize(eaccelerator_get("my_key"));

Restart apache2

PHP Extend Session Timeout

Posted on Monday, May 10, 2010 in Linux, PHP

Edit session.gc_maxlifetime param in php.ini file:
session.gc_maxlifetime = 1440

Unicode data in a Unicode-only collation

Posted on Thursday, April 15, 2010 in Linux, PHP

PHP Error on MSSQL query:
Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library

Edit /etc/freetds/freetds.conf (Ubuntu)
uncomment line:
;tds version = 4.2
and change to:
tds version = 8.0

Generic Object

Posted on Friday, October 2, 2009 in PHP

class GenericObj {
function __call($method, $args) {
$var = strtolower(substr($method, 4, 1)) . substr($method, 5);
switch (substr($method, 0, 4)) {
case "pull": return $this->{$var}; break;
case "push": $this->{$var} = $args[0]; break;
} // switch
} // call
} // GenericObj

Truncate Function

Posted on Friday, October 2, 2009 in PHP

public function truncate($str, $limit, $break = " ", $pad = "...") {
if(strlen($str) > $limit) {
$str = substr($str, 0, $limit);
if(false !== ($breakpoint = strrpos($str, $break))) {
$str = substr($str, 0, $breakpoint);
} // if
$str = $str . $pad;
} // if
return($str);
} // truncate

PHP Time Zone

Posted on Thursday, October 1, 2009 in PHP

Set PHP time zone:

date_default_timezone_set('America/New_York');

Replace Image Color

Posted on Sunday, August 16, 2009 in PHP

$imgname = "img.gif";
$im = imagecreatefromgif ($imgname);
$index = imagecolorclosest ( $im, 2,2,254 ); // get White COlor
imagecolorset($im,$index,255,255,255); // SET NEW COLOR
$imgname2 = "result.gif";
imagegif($im, $imgname); // save image as gifimagedestroy($im);
echo("origin image: <img src="\"".$imgname."\" />");
echo("new image: <img src="\"".$imgname2."\" />");

Replace Email

Posted on Monday, August 10, 2009 in PHP

$pattern='|(\S+)\@(.*)\.(\S+)|is';
$msg=preg_replace($pattern, '< a href="mailto:$1@$2.$3">$1@$2.$3< /a >', $msg);

Replace URL

Posted on Monday, August 10, 2009 in PHP

$pattern='|http://(\S+)|is';
$msg=preg_replace($pattern, '< a href="http://$1" target="_blank">http://$1< /a >', $msg);