Note: This post is over two years old and so the information contained here might be out of date. If you do spot something please leave a comment and we will endeavour to correct.
9th January 2009 - 5 minutes read time
Aside from assigning and using your own properties Phing also comes with a set of built in properties that can be used to find out all sorts of information regarding the system that Phing is run on.
As an example, let's say you wanted to found out the operating system that phing is being run on. In this case you would use the variable host.os, which on a Windows XP system would print out WINNT.
There are a lot of different properties available, so I have included the table from the phing website at the bottom of this post as a reference. However, there is one special variable called env that needs further explanation. The env variable references any environment variables that have been set. For example, if you set an environment variable using the following shell command (on UNIX based systems only).
export TESTVAR=mytestvar
You can now reference this in your build.xml file by using the following.
${env.TESTVAR}
Here is a table of the built in properties available.
Property
Contents
application.startdir
Current work directory
env.*
Environment variables, extracted from $_SERVER.
host.arch
System architecture, i.e. i586. Not available on Windows machines.
host.domain
DNS domain name, i.e. php.net. Not available on Windows machines.
host.fstype
The type of the filesystem. Possible values are UNIX, WINNT and WIN32
host.name
Operating System hostname as returned by posix_uname(). Not available on Windows machines.
host.os
Operating System description as set in PHP_OS variable (see PHP Manual).
host.os.release
Operating version release, i.e. 2.2.10. Not available on Windows machines.
host.os.version
Operating system version, i.e. #4 Tue Jul 20 17:01:36 MEST 1999. Not available on Windows machines.
line.separator
Character(s) that signal the end of a line, "\n" for Linux, "\r\n" for Windows system, "\r" for Macintosh.
os.name
Operating System description as set in PHP_OS variable.
phing.file
Full path to current buildfile.
phing.home
Phing installation directory, not set in PEAR installations.
phing.version
Current Phing version.
phing.project.name
Name of the currently processed project.
php.classpath
The value of the environment variable PHP_CLASSPATH.
php.version
Version of the PHP interpreter. Same as PHP constant PHP_VERSION (see PHP Manual).
I have found that even though some of variables specifically say "not available on Windows" most of them will produce some sort of output, even on Windows machines. Here is a test build.xml file that you can use to see what the different variables print out on your system.
Thanks, that was very useful. I was looking for a variable to find what OS version you are running and solved by simple creating my own property value from the output of a Linux command:host.os.distro ${host.os.distro}Which shows for example:
[echo] host.os.distro Ubuntu 10.04.4 LTS \n \l
Submitted by Angel Abad on Wed, 02/05/2014 - 13:03
Running complex tasks in Phing can mean running out of memory, especially when altering or changing lots of files. I was recently working on a image sorting Phing project that sorted images based on EXIF information.
Providing a Phing build file along with a project is a good way of allowing automation of certain aspects of the project. The only trouble is that users won't know what's in the build file unless they open it or just run it.
Phing has a few different tasks and elements that allow you to select paths of code execution depending on what you need to happen in a build file. These are limited to loops and if statements, but a lot of functionality can be covered with just a couple of lines of XML.
The other day I was experimenting with Git hooks. These are scripts that you can execute before certain actions are run in Git. For example, you might want to ensure that forced updates are not run, ensuring respository files have the correct permissions after merging, or that the files have ASCII standard names before being committed.
I use Phing for a lot of different tasks, it helps me to automate things that I would otherwise mess up if left to my own devices. Prime candidates for Phing scripts are things that I don't do that much and forget how to do them, or that have a number of complex steps.
Checking Syntax Errors In PHP And JavaScript Using Phing
Running a simple syntax check over your files is a good way to save time. This can be when testing code but best practice is to not to even commit code that contains syntax errors.
Comments
Submitted by Angel Abad on Wed, 02/05/2014 - 13:03
PermalinkAdd new comment