Moving PHP Solutions from Windows to Linux

17th December, 2011 – 11:16 am

I’m currently building a ticketing / holiday booking application in my spare time in PHP / MySQL.  When I started in PHP I used Linux for my development platform because my laptop ran, the rather terrible, Windows Vista.  I’ve since upgraded to Windows 7 and find myself using this instead of my Linux share now (oh the shame!).

I develop using the excellent WAMP Server  and then copy up to a cheapie Linux host I have.  What could possibly go wrong?!

Well for a start there are obvious configuration difference issues (trying to keep the same versions of PHP and its extensions.  I have the error settings set to be as verbose as possible to try and trap issues in my coding before I set the code lose on the server (these are not exposed on the website so that you don’t expose the error out to web visitors – security risks) but aside from that I’d expect PHP that runs fine and dandy hosted on my Windows dev platform to be the same on the Linux server – BIG ASSUMPTION!

com_create_guid – Creating GUIDS – Works on Windows, Not on Linux

When you look at the name of the function you’ll quickly realise that this is Windows only. I’m in the (dirty?) habit of using GUIDS due to my Windows / .NET background (my current and all of my previous employers have been solely .NET) – didn’t think about this before I sprayed the use of this function across my code.


I’ve found this function from here to be the best.

A guid function that works in all php versions:


function guid(){

   if (function_exists(‘com_create_guid’)){

       return com_create_guid();


       mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.

       $charid = strtoupper(md5(uniqid(rand(), true)));

       $hyphen = chr(45);// “-“

       $uuid = chr(123)// “{“

               .substr($charid, 0, 8).$hyphen

               .substr($charid, 8, 4).$hyphen

               .substr($charid,12, 4).$hyphen

               .substr($charid,16, 4).$hyphen


               .chr(125);// “}”

       return $uuid;



echo guid();


Formatting Money money_format()

Now this one staggers me… surely this is a fundament function when building PHP web applications!?  Yup – doesn’t work in Windows.  I’m guessing this is due to the localisation of this function.


Not found a complete work around but suggest you use number_format() instead and prefix your currency… 🙁

Decoding JSON Strings Fails json_decode

This one I suspect is more of a PHP config issue but I’ll note it here.  Magic quotes causes issues with JSON strings. Before you run the json_decode it’s worth checking and striping the ‘helpful’ slashes!


 // stupid magic quotes is a pain. (moving from PHP on Windows to linux)


 $bookingBasket = stripslashes($_REQUEST[‘basket’]);

 } else{

 $bookingBasket = $_REQUEST[‘basket’];


 $bookingBasket = json_decode($bookingBasket,true);

I’d be very interested to hear of other solutions for the above stevemorgan [@] uk2. net


Post a Comment