Commandline scripting in PHP 5

At TriMM I am working on an eLearning environment consisting of a core engine and some 500 swfs (and growing). Some of these locations are very simple, like an image with hotspots and some are more complex such as an emailclient. The engine is refactored now and then, and extended, in addition the requests for some of the locations themselves might change.
All the work is done by different people in different roles, and some location versions might or might not be compatible with certain version of the core engine.

Why am I telling you this? Because I switched from Flash to PHP because of this? 🙂 No way.

But I do have to write a script to automate the release process, which will collect the latest versions of all location swf’s that go with a certain core engine version. I thought about using Ruby or Python for that, but since TriMM does a lot of Java, PHP and Flash, I decided it had to be one of those 3.

My first choice was PHP since it is a scripting language and doesn’t have to be compiled. Having written a little bit in it, I’m not so sure if I’m gonna stick with my choice since me and untyped functional languages dont really match, but okay okay I’ll try.

I tried PHPEclipse but that wasn’t working for me, so hopefully this setup will work, these are the steps I took. By the way this cost me the better of 2 days to figure out, all because of the all so wonderfull platform called eclipse. Installing everything separate was easy, getting it to work was next to impossible, due to missing depencies. The fun thing is that eclipse tells you what it’s missing, but not where to find it. Neither does Google, except in some very obscure way. In the end, there is apparently an all in one bundle for PDT, so I settled for that.

God I’m loving folks who keep it simple such as the FlashDevelop crew. This is a good example of expensive open source software, since with all the hours I invested to get this damn simple PDT thing to work I could have bought a lightweight php editor.

  1. download the I downloaded the latest WTP releases first, but couldn’t get them to work.
  2. extract the zip to a directory c:\program files\eclipse\
  3. drag the eclipse.exe to the startmenu to add it:) (right mouse button, create shortcut)
  4. install the java runtime environment if necessary from
  5. run eclipse
  6. I am executing my php on the commandline, and using a batch file to do so, which has the following content:
    php -a sources\generateDeploymentScript.cmdphp -include=%CD%\include.txt -alwaystrunk

    As you can see, I’m using the -a option to show how far the script has gotten even if errors are occuring and I’ve renamed the .php to cmdphp to show that the script is meant to run from a commandline and should’nt be mistaken for a webserver script.
    Dragging this batchfile to the eclipse environment causes it to be executed, which is not what we want.
    Fix this by following these steps:
    Goto Window -> Preferences -> +General+Editors+File Assocations -> Add *.bat and associate a Text Editor with it

    In addition the cmdphp isnt recognized so add that as well, and associate it with the PHPEditor.

  7. Open the cmdphp file, in my case it gave another warning, and a content type link to fix the problem. I looked up the PHP Content Type in the Filtered Preferences dialog, and added cmdphp there as well. Close the cmdphp file and open it again and voila!
  8. In order to run the script within eclipse and see some output, goto Run, External Tools, Open External Tools Dialog. I added my batch file as an external tool, entering only the location and working directory.
  9. Next in order to have the errors be shown in the console as well, I went into my PHP 5 directory (downloaded from and opened the php.ini file and changed this setting:
    display_errors = On
    Note that you shouldn’t do this if the same PHP 5 distribution is being used for live website deployment, due to security issues that could arise.
  10. If necessary goto Window -> Preferences -> General -> Editors -> Text Editors and turn on line numbers

And tadaa done.

When you’ve finally figured something out, it’s always so simple in hindsight.
So what took me so long? Downloading the wrong distributions, downloading the wrong plugins to try etc.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *