tag “phing”
how to use phing to build php projects
by Hamid Reza Fahimi Madjd @ Jun 25, 2011
Some days ago I found a solution to build php project that called Phing.
Phing is a build framework based on Apapche Ant. If you are familiar with Ant and its role in Java *E projects, you can learn Phing very fast.
Like Ant, there is a (or more) build file named build.xml (default name) to define operations that you like occur on your project.
Now i'm going to describe it by a practical example:
Consider a php project with following structure:
Project |_src |__package1 |___class1.php |___class2.php |__package2 |__package3 |_static |_templates .htaccess build.xml config.php index.php
Scenario:
I want "build.xml" do following operations:
- export project from subversion repository and copy it to a temp directory
- make an archive file and name it based on latest version number
- copy archive file to a remote server over ssh (scp)
I made build.xml file put following code in it:
<?xml version="1.0" encoding="UTF-8"?> <!-- define project name and default target --> <project name="my-project" default="dist"> <!-- define some properties (variables) --> <property name="path.dive.root" value="/home/hamid/temp" /> <property name="path.dive" value="${path.dive}/${phing.project.name}" /> <!-- empty related temp directory (delete old one and create new one) --> <target name="prepare"> <echo msg="delete and create ${path.dive} directory" /> <delete dir="${path.dive}" includeemptydirs="true" verbose="true" failonerror="true" /> <mkdir dir="${path.dive}" /> </target> <target name="build" depends="prepare"> <!-- export project from reposiroey and copy to temp directory --> <svnexport svnpath="/usr/bin/svn" username="username" password="password" force="true" nocache="true" repositoryurl="svn://localhost/${phing.project.name}/" todir="${path.dive}"/> <!-- get latest version number and save in svn.lastrevision property --> <svnlastrevision svnpath="/usr/bin/svn" workingcopy="${path.source}" repositoryurl="svn://localhost/${phing.project.name}" propertyname="svn.lastrevision"/> <!-- generate archive file name --> <property name="archive.filename" value="${phing.project.name}-v${svn.lastrevision}.tar.gz" /> </target> <target name="dist" depends="build"> <!-- archive directory and save it --> <tar destfile="${path.dive.root}/${archive.filename}" basedir="${path.dive}" compression="gzip"/> <!-- copy archive file and copy to sources foler on remote server --> <scp username="username" password="password" host="host" todir="sources/" file="${path.dive.root}/${archive.filename}" /> </target> </project>
after that go to path that build file is there and type:
$ phing
cause build file name is build.xml, it's not necessary to specify it.
Also if you use PhpStorm, you can add build.xml to Phing Build tool window and deal with that inside the IDE.
Now, I did build process just in 10 Seconds instead of 5 Minutes.
I hope this example encourage you to use Phing.
You can get more detail information from its website.
phing, php no comment
recent posts
- › how to use phing to build php projects
- › slice/paging large contents using php
- › how to log methods call in php ?
- › sql IN logical operation for java
- › backup from mysql database's routines
- › how to deploy war file into web root ?
- › how to get all oracle components version ?
- › temporary/memory tables in mysql
- › Set JFreeChart data from database
- › How to search and sort primitive arrays in Java ?
archive
- › 2011/06 (1)
- › 2010/11 (1)
- › 2010/10 (1)
- › 2009/04 (2)
- › 2008/05 (1)
- › 2008/03 (1)
- › 2008/01 (4)
- › 2007/12 (4)
last tweet
- ›