Discover PHP 5.4

Finally i had the time to have a look at PHP 5.4, as i heard it had built in web server ( a cool feature for a windows user).

To shortly describe my requirements: a on demand webserver for Windows systems that would understand php, would allow easy configuration, a rewrite mechanism and preferably would not require any install process. All the criteria above were successfully implemented in php 5.4 as explained here.

I was able to run some quite basic projects on it, but when it came to running a complex framework that took advantage of the mod_rewrite available in Apache, i have observed that it requires to rewrite all your rewrite rules (i haven’t found any better formula to express this ) in a php file called router.php. Not complicated as most of the advance frameworks(Zend,Symfony) require only 1 or 2  generic rules to be defined, but still it’s an extra file that should be maintained in case you want to use this structure on your developer environment.
For those who find suitable for their needs i’ll share a bat script that can make the start of this webserver more barable:

@ECHO OFF
ECHO Project selector
ECHO A: D:workspacealex-cv
ECHO B: D:workspaceinfoip
ECHO C: D:workspaceSymfony_Standard_2.0.17
ECHO D: D:workspacewakeup
ECHO X: D:workspace
REM #############################################################
REM ## for /C you can add as many variants as you want #
REM ## like /C ABCDEFGHI based on to order of the letter #
REM ## you'll get an error level that you can use bellow #
REM #############################################################
CHOICE /C ABCX /N /M "Decide project"
IF ERRORLEVEL 1 SET PROJECT=D:workspacealex-cv
IF ERRORLEVEL 2 SET PROJECT=D:workspaceSymfony_Standard_2.0.17web
IF ERRORLEVEL 3 SET PROJECT=D:workspacewakeupweb REM https://github.com/alexbumbacea/wakeup
IF ERRORLEVEL 4 SET PROJECT=D:workspace
ECHO You chose to start project %PROJECT%
php -S 127.0.0.1:80 -t %PROJECT%

Another cool thing is that they now accept a syntax for defining arrays more similar to javascript:

$a = ['alex', 'blog', 'review'];
$a = [ 'key' => 'value', 'key2' => 'value2']

Beside the above mentioned features there is also some other stuff that worth mentioning:

  • Traits – not a day by day thing for me, but still allows greater modularity
  • Function array de-referencing – usefull, but it makes the code more un-readable – (new Class())->function();
  • Upload progress in session – very nice

Anyway since most of the hosting accounts that i work with are 5.3, i will not be able to use this new features. 🙁

Leave a Reply