PHP 5.1+ Date vs Strftime Timezone Annoyance
In the old PHP4 days, you could change the default timezone by: putenv("TZ=America/Los_Angeles");. In php5, you can still do this and it’ll work for strtotime, strftime, gmstftime (maybe more). It will not work for methods date and gmdate. For those, starting in version 5.1, you’ll need to call date_default_timezone_set("America/Los_Angeles");. This is just another one of those annoying things that make PHP a dying language.
Together, to be cross-version compliant:
putenv("TZ=America/Los_Angeles"); if( function_exists("date_default_timezone_set") ) { date_default_timezone_set("America/Los_Angeles"); }
We need both to be reverse-compatible with PHP4.
The little known PHP htmlspecialchars
Want to replace only xml entities <, >, &? Don’t use htmlentites or str_replace; use htmlspecialchars.
The only named entities for XML are &, > and <. For all others you need to use the Unicode character code (eg.  ).
Webkit: Entity ‘nbsp’ not defined – Convert HTML entities to XML
PHP 5.3.1 Error Logging and Display of Said Errors
I just installed the PHP 5.3.1 Windows installer bundle [VC9 x86 Non Thread Safe (2009-Nov-19 09:53:39)] on my Windows 7 [Ultimate] machine. I want the PHP error output to get sent to stderr when run from the command line. I don’t want the errors logged to a file because I’m developing cli tools. Since we’re dealing with the cli, I also don’t want html errors. Should be pretty easy… if you know how to edit the settings.
These worked for me:
error_reporting = E_ALL display_errors = stderr display_startup_errors = On log_errors = Off html_errors = Off ;error_log = php-errors.log
Ensure that error_log is not set, otherwise error will not be displayed. This problem may be related, but is obviously not, the date bug mentioned in the PHP bug reports. It may be fixed in the latest snapshot. As a note, the php.ini date.timezone setting is date.timezone = "Pacific/Honolulu", and I still had this problem.
Other things I noticed:
When error_log = syslog, you can find the PHP events in the windows Event Viewer -> Windows Logs -> Application. I mention it in case you want that type of thing… or think error that logging may not be working.
PHP/GD Bug: imageFilledEllipse Centered on Y=0
I was drawing circles using PHP’s GD function imageFilledEllipse. I noticed that when I went to draw a circle having its center at $y=0,there would be a line missing at $y=1.
Here’s the work-around:
if( -1 <= $py && $py <= 1 ) { // Undocumented PHP bug when Y coordinate is zero. imageFilledEllipse($img,$px,$py,$X,$X,$color); imageFilledRectangle($img,$px-$halfX,$py-1,$px+$halfX,$py+1,$color); } else { imageFilledEllipse($img,$px,$py,$X,$X,$color); }
PHP Version:
PHP 4.3.9 (cgi) (built: Apr 1 2009 10:41:42) Copyright (c) 1997-2004 The PHP Group Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
$ yum search php-gd
php-gd.i386 4.3.9-3.26 installed Matched from: php-gd The php-gd package contains a dynamic shared object that will add support for using the gd graphics library to PHP.
Compiling Datascope.so for PHP
Does the following sentence make sense?
In order to be able to simply dl(“Datascope.so”) in your PHP code, you first need to make sure Datascope.so is compiled and copied to the extension_dir, as specified in php.ini (ex: /usr/lib/php4).
Answer:
No: Stop right now. You’re not qualified to read this article.
Yes: Keep reading.
Notes
You’re not compiling the PHP source code for actual use, so please don’t install it. If you do, you run the risk of clobbering any pre-existing php installations, and overwriting previously compiled-in modules. The only reason why you ”make” PHP is so that the Zend libraries are properly initialized.
The PHP ”make” step may be avoidable, but given that the compile doesn’t affect system performance, I didn’t bother.
Paths should be changed to reflect your setup. If you don’t have the src/contrib/data/php/datascope code, you can get it from the contrib source at BRTT’s web site.
Contrib appears to be maintained by Indiana University.
Paths
- Antelope Bash Script ”/opt/antelope/4.9/setup.sh”
- Datascope Source ”/opt/antelope/4.9/src/contrib/data/php/datascope”
- PHP Source Code URL ”http://downloads.php.net/ilia/php-5.1.4.tar.bz2”
- PHP Modules Directory ”/usr/lib/php/modules/”
Compile and Install Steps
- wget <PHP Source Code>
- bunzip2 php-5.1.4.tar.bz2
- tar xf php-5.1.4.tar
- cd php-5.1.4
- PHP_INC=`pwd`
- export PHP_INC
- ./configure
- make
- cd <Datascope Source>
- source <Antelope Bash Script>
- sudo make install
- sudo cp Datascope.so <PHP Modules Directory>
PHP Script Example
Proper usage of the ”Datascope.so” module follows:
putenv( "PFPATH=/opt/antelope/4.9/data/pf" ); putenv( "ANTELOPE=/opt/antelope/4.9" ); set_include_path( get_include_path().PATH_SEPARATOR.getenv('ANTELOPE')."/data/php" ); if( !extension_loaded( "Datascope.so" ) ) { dl( "Datascope.so") || exit( "Failed to load datascope.so" ) ; }