<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>I Don&#039;t Blog</title>
	<atom:link href="http://pascaldevink.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://pascaldevink.wordpress.com</link>
	<description>Random thoughts about all things development</description>
	<lastBuildDate>Wed, 28 Oct 2009 23:02:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='pascaldevink.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>I Don&#039;t Blog</title>
		<link>http://pascaldevink.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://pascaldevink.wordpress.com/osd.xml" title="I Don&#039;t Blog" />
	<atom:link rel='hub' href='http://pascaldevink.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Input validation and error messages using Zend Form</title>
		<link>http://pascaldevink.wordpress.com/2009/10/29/input-validation-and-error-messages-using-zend-form/</link>
		<comments>http://pascaldevink.wordpress.com/2009/10/29/input-validation-and-error-messages-using-zend-form/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 23:02:57 +0000</pubDate>
		<dc:creator>pascaldevink</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[Zend]]></category>

		<guid isPermaLink="false">http://pascaldevink.wordpress.com/?p=41</guid>
		<description><![CDATA[One thing I like about Zend, is the option to let it build your forms for you. You can mix and match form elements just as you would with regular objects and in the end, let Zend build the form for you. You can use regular textboxes, radio buttons, submit buttons, etc and even the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=41&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One thing I like about Zend, is the option to let it build your forms for you. You can mix and match form elements just as you would with regular objects and in the end, let Zend build the form for you. You can use regular textboxes, radio buttons, submit buttons, etc and even the occasional date picker is not a problem if you are using Zend X.</p>
<p>One thing that was giving me some problems though, was displaying error messages. It is always nice to give good feedback to your users with a nice, meaningful message about what was wrong with the input they provided.<br />
<span id="more-41"></span><br />
To accomplish this, I build the form, consisting of a first name, infix, last name and email address.<br />
Before reading on, I must mention that wordpress screwed up my code formatting, but your IDE should be able to make something good out of it.</p>
<p><code><br />
$this-&gt;setAction($this-&gt;_actionUrl)<br />
-&gt;setMethod('post')<br />
-&gt;setAttrib('id', 'signupform')<br />
<br />
$this-&gt;addElement('text', 'firstname', array('label' =&gt; 'First name'));<br />
$username = $this-&gt;getElement('firstname')<br />
-&gt;addValidator('alnum')<br />
-&gt;setRequired(true)<br />
<br />
$this-&gt;addElement('text', 'infix', array('label' =&gt; 'Infix'));<br />
$username = $this-&gt;getElement('infix')<br />
-&gt;addValidator('alnum')<br />
-&gt;setRequired(false)<br />
<br />
$this-&gt;addElement('text', 'lastname', array('label' =&gt; 'Last name'));<br />
$username = $this-&gt;getElement('lastname')<br />
-&gt;addValidator('alnum')<br />
-&gt;setRequired(true)<br />
<br />
$this-&gt;addElement('text', 'email', array('label' =&gt; 'Email address'));<br />
$email = $this-&gt;getElement('email')<br />
-&gt;addValidator('EmailAddress')<br />
-&gt;setRequired(true)<br />
<br />
$submit = $this-&gt;addElement('submit', 'Signup');<br />
</code></p>
<p>I can now stick this into my views using:<br />
Controller:<br />
<code>$form = new SignupForm('/user/signup');<br />
$this-&gt;view-&gt;form = $form;</code><br />
View:<br />
<code>&lt;?php echo $form; ?&gt;</code><br />
Refreshing the page should now give you a simple form with a submit button. This form does nothing now though, and we could use some interaction at the end:<br />
<code>public function signupAction() {<br />
  $form = new SignupForm('/user/signup');<br />
  if ($this-&gt;_request-&gt;isPost()) {<br />
    if ($form-&gt;isValid($this-&gt;getRequest()-&gt;getPost())) {<br />
      echo "Congratulations, your form validated";<br />
    }<br />
  }<br />
}</code><br />
As you can see here, we are actively checking if the form was indeed valid. Remember the validators we added to the form? The Zend Form is smart enough to iterate over the elements with values from the POST and decide whether or not the input is valid. It doesn&#8217;t stop there though, it continues iterating until the end, all the while collecting error messages from the validated input.<br />
Before displaying what was wrong with the user&#8217;s input, we must first add these messages somewhere. We add them to the form, as that is where they belong:<br />
<code>$this-&gt;addElement('text', 'firstname', array('label' =&gt; 'First name'));<br />
$username = $this-&gt;getElement('firstname')<br />
-&gt;addValidator('alnum')<br />
-&gt;setRequired(true)<br />
-&gt;addErrorMessage("Something was wrong with your first name");<br />
<br />
$this-&gt;addElement('text', 'lastname', array('label' =&gt; 'Last name'));<br />
$username = $this-&gt;getElement('lastname')<br />
-&gt;addValidator('alnum')<br />
-&gt;setRequired(true)<br />
-&gt;addErrorMessage("Something was wrong with your lastname");<br />
<br />
$this-&gt;addElement('text', 'email', array('label' =&gt; 'Email address'));<br />
$email = $this-&gt;getElement('email')<br />
-&gt;addValidator('EmailAddress')<br />
-&gt;setRequired(true)<br />
-&gt;addErrorMessage("Something was wrong with your email");</code></p>
<p>These messages could be nicer and could even be retrieved from a language table if you want. You could also add messages that are returned depending on what kind of validation went wrong.<br />
For now, let&#8217;s leave it this way and display the messages to our user:<br />
<code>if ($form-&gt;isValid($this-&gt;getRequest()-&gt;getPost())) {<br />
// Your validated form code<br />
else {<br />
$messages = $form-&gt;getErrors();<br />
$this-&gt;view-&gt;formResponse = $messages;<br />
}</code><br />
This was what stomped me a little in the beginning. The form has a method called getErrorMessages() and since we added the messages to our form elements using addErrorMessage(), it seemed only logical to retrieve these with aforementioned method. For reasons unknown to me, the Zend team decided it was best to use getErrors().</p>
<p>Feel free to make this prettier and perhaps trow in some AJAX to make this more dynamic.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pascaldevink.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pascaldevink.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pascaldevink.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=41&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pascaldevink.wordpress.com/2009/10/29/input-validation-and-error-messages-using-zend-form/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/15bd509601f2b058f9d6edf45302dff0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pascaldevink</media:title>
		</media:content>
	</item>
		<item>
		<title>Zend REST client and grails REST server</title>
		<link>http://pascaldevink.wordpress.com/2009/10/18/zend-rest-client-and-grails-rest-server/</link>
		<comments>http://pascaldevink.wordpress.com/2009/10/18/zend-rest-client-and-grails-rest-server/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 20:28:06 +0000</pubDate>
		<dc:creator>pascaldevink</dc:creator>
				<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Zend]]></category>
		<category><![CDATA[Zend framework]]></category>

		<guid isPermaLink="false">http://pascaldevink.wordpress.com/?p=27</guid>
		<description><![CDATA[It can sometimes be hard to find out how different systems work are able to work together. Take for example a grails application which features some REST interface. And for that same example, let&#8217;s take a PHP application made with the excellent Zend framework, which wants to use the aforementioned grails application to retrieve some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=27&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It can sometimes be hard to find out how different systems work are able to work together. Take for example a grails application which features some REST interface.<br />
And for that same example, let&#8217;s take a PHP application made with the excellent Zend framework, which wants to use the aforementioned grails application to retrieve some data, or, add some data.<br />
Without further ado, here are the important code snippets for both applications, starting with the server-side. To find out more about grails and REST, look <a href="http://grails.org/doc/latest/guide/13.%20Web%20Services.html#13.1 REST">here</a>. To find out more about Zend and REST, look <a href="http://framework.zend.com/manual/en/zend.rest.html">here</a>.<br />
<span id="more-27"></span><br />
Let&#8217;s say we have a grails controller called Signup, which has a save function:<br />
<code><br />
def save = {<br />
def sdfh = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")<br />
params.signupdate = sdfh.parse(params.signupdate)<br />
def u = new Signup()<br />
u.properties = params<br />
if (u.save()) {<br />
render u as XML<br />
} else {<br />
render u.errors as XML<br />
}<br />
}<br />
</code></p>
<p>And a form with a couple of fields which eventually calls this method:<br />
<code><br />
public function signupAction() {<br />
$this-&gt;view-&gt;title = 'Signup';<br />
$form = new SignupForm('/user/signup');<br />
$this-&gt;view-&gt;formResponse = '';<br />
if ($this-&gt;_request-&gt;isPost()) {<br />
if ($form-&gt;isValid($_POST)) {<br />
$signupdate = new Zend_Date();<br />
$client = new Zend_Rest_Client('http://localhost:8080');<br />
$data = array('surname'=&gt;$this-&gt;_getParam('firstname'),<br />
'infix'=&gt;$this-&gt;_getParam('infix'),<br />
'lastname'=&gt;$this-&gt;_getParam('lastname'),<br />
'email'=&gt;$this-&gt;_getParam('email'),<br />
'signupdate' =&gt; $signupdate-&gt;toString('yyyy-MM-dd hh:mm:ss'));<br />
$response = $client-&gt;restPost('/yourapp/signups', $data);<br />
} else {<br />
$this-&gt;view-&gt;formResponse = 'Sorry';<br />
}<br />
}<br />
$this-&gt;view-&gt;form = $form;<br />
}<br />
</code></p>
<p>This should not be too hard to use in your own application. If you need more explanation or more of the code I used, please ask in the comments.</p>
<p>Edit: I see wordpress messed up the code blocks, so for a more easy-to-read version, check the <a href="http://gist.github.com/212825">both</a> <a href="http://gist.github.com/212827">gist</a> files</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pascaldevink.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pascaldevink.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pascaldevink.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=27&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pascaldevink.wordpress.com/2009/10/18/zend-rest-client-and-grails-rest-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/15bd509601f2b058f9d6edf45302dff0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pascaldevink</media:title>
		</media:content>
	</item>
		<item>
		<title>Speed up phars using your own stub</title>
		<link>http://pascaldevink.wordpress.com/2009/10/16/speed-up-phars-using-your-own-stub/</link>
		<comments>http://pascaldevink.wordpress.com/2009/10/16/speed-up-phars-using-your-own-stub/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 13:48:52 +0000</pubDate>
		<dc:creator>pascaldevink</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Phar]]></category>

		<guid isPermaLink="false">http://pascaldevink.wordpress.com/?p=16</guid>
		<description><![CDATA[After posting my article about phars, I came across a Dutch website with an article about the subject and they also discuss the performance of phar files. This post is thus a shameless translated copy of the original article. It seems that phar is always 33% slower then normal php files. This should not be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=16&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After posting my article about phars, I came across a Dutch website with an <a href="http://www.scriptorama.nl/howtos/php-53-de-phar-extensie">article</a> about the subject and they also discuss the performance of phar files.<br />
This post is thus a shameless translated copy of the original article.<br />
<span id="more-16"></span><br />
It seems that phar is always 33% slower then normal php files. This should not be happening, as the authors claim a <em>negligible difference</em> between a webapplication from a phar and a webapplication directly from the file system. An email send to the original author of the phar extension brought some clarity: try using your own, shorter stub then the ones supplied and that was a great help!</p>
<p>A standard stub containt PHP code that allows a phar file to also run on PHP 5.2 installations. As the 5.2 version does not come with the phar extension build-in, this piece of code needs to jump some hoops in order to be able to run the phar file. This shows in the file size: the stub is about 7KB of PHP code.</p>
<p>If you remove references to the standard stub and only use that what is necessary for PHP 5.3, the performance increases to a rate which is comparable to webapplications that are read directly from the file system:<br />
<code><br />
&lt;?php<br />
$phar = new Phar('project-0.1.phar', 0, 'project.phar');<br />
$phar-&gt;buildFromDirectory('project/');<br />
$phar-&gt;setStub("&lt;?php<br />
Phar::interceptFileFuncs();<br />
set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());<br />
Phar::webPhar(null, \$web);<br />
include 'phar://' . __FILE__ . '/' . Extract_Phar::START<br />
return;<br />
__HALT_COMPILER(); ?&gt;");<br />
?&gt;<br />
</code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pascaldevink.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pascaldevink.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pascaldevink.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=16&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pascaldevink.wordpress.com/2009/10/16/speed-up-phars-using-your-own-stub/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/15bd509601f2b058f9d6edf45302dff0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pascaldevink</media:title>
		</media:content>
	</item>
		<item>
		<title>Use phars like wars in enterprise environments</title>
		<link>http://pascaldevink.wordpress.com/2009/10/16/use-phars-like-wars-in-enterprise-environments/</link>
		<comments>http://pascaldevink.wordpress.com/2009/10/16/use-phars-like-wars-in-enterprise-environments/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 08:03:14 +0000</pubDate>
		<dc:creator>pascaldevink</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Phar]]></category>

		<guid isPermaLink="false">http://pascaldevink.wordpress.com/?p=11</guid>
		<description><![CDATA[Developers coming from a Java background have access to multiple containers, such as jar and war. Each is essentially a zip file with a standard layout and executable content (and often no compression to keep things speedy). With the build-in introduction of Phar in PHP 5.3, we now have a similar powerful  tool in our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=11&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Developers coming from a Java background have access to multiple containers, such as jar and war. Each is essentially a zip file with a standard layout and executable content (and often no compression to keep things speedy).<br />
With the build-in introduction of Phar in PHP 5.3, we now have a similar powerful  tool in our PHP hands. Read on to see how phar archives can be used to ease deployment and in the future might bring a lot of new functionality, but first read up on some <a href="http://php.net/manual/en/book.phar.php">phar</a> <a href="http://www.pabloviquez.com/img_blog/PharFiles_114F8/phar_schematic_tech_summit_2008.pdf">introductions</a> and specially the <a href="http://www.nickawilliams.com/2008/09/04/the-new-phar-php-package/">performance</a> questions.<br />
<span id="more-11"></span><br />
First, we need an application to phar. This can be anything, from a simple Hello World, to a full blown Zend Framework application. The important thing to remember is that phar currently has its limitations, like:</p>
<ul>
<li>The concept of &#8220;current directory&#8221; has no meaning in a stream wrapper</li>
<li>chdir() and getcwd() only work for directories stored on physical disks. All references to chdir() or getcwd() therefore needed to be modified by hand.</li>
<li>All uses of opendir() that reference internal application code had to either use dirname(__FILE__) or be hand-modified.</li>
</ul>
<p>So check if your application isn&#8217;t affected by the above issues.</p>
<p>First, we need to create a PHP script that handles the phar creating for us. Other then the Java counterpart, PHP allows for more configuration about how a phar file is created.<br />
We could call this file <em>makephar.php</em>:<br />
<code><br />
&lt;?php<br />
$phar = new Phar('project-0.1.phar', 0, 'project.phar');<br />
$phar-&gt;buildFromDirectory('project/');<br />
$phar-&gt;setStub('&lt;?php Phar::webPhar(); __HALT_COMPILER(); ?&gt;');<br />
?&gt;<br />
</code><br />
This piece of code creates a phar called project-0.1.phar with an alias of project.phar, adds all the content of &#8216;/&#8217; and creates a webPhar; more on that later.<br />
If you execute this from your command line:<br />
<code><br />
$ php -d phar.readonly=0 build-phar.php<br />
</code><br />
Or from a browser if the file is publicly available (not secure though), you&#8217;ll see that the phar file is created and ready to be used.</p>
<p>You can now deploy this file to your apache documentroot and call it from the browser. This can be done by either adding support for phar files to apache:<br />
<code><br />
AddType application/x-httpd-php .php .phtml .phar<br />
</code><br />
Or by renaming the phar file to a PHP file and calling that. The Phar::webPhar() method parses  <var>$_SERVER['REQUEST_URI']</var> and routes a request from a web browser to an internal file within the phar archive.  In essence, it simulates a web server, routing requests to the correct file, echoing the correct headers and parsing PHP files as needed.  This powerful method is part of what makes it easy to convert an existing PHP application into a phar archive.<br />
You can now start playing around with APC or other caching mechanisms to speed things up, but I&#8217;ll leave that up to you.</p>
<p>Other things you can do with Phar files include easy deployment, for example with <a href="http://www.capify.org/index.php/Capistrano">capistrano</a> and automate the entire process. This could be coupled with you SVN tags to automaticaly create and deploy a phar on a test site upon creating a new SVN tag.<br />
I also see a brighter future for those web-ftp-and-edit-online scripts, which normally pose somewhat of a security-threat while not adding much-needed functionality. Similar to Apache Tomcat&#8217;s manager, a apache manager could be made where it would be easy to drop-in your application and perhaps even have it run sandboxed.</p>
<p>Let your fantasy run free and share your ideas about what Phar can bring us</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pascaldevink.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pascaldevink.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pascaldevink.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=11&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pascaldevink.wordpress.com/2009/10/16/use-phars-like-wars-in-enterprise-environments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/15bd509601f2b058f9d6edf45302dff0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pascaldevink</media:title>
		</media:content>
	</item>
		<item>
		<title>The hell that is unicode</title>
		<link>http://pascaldevink.wordpress.com/2009/10/15/the-hell-that-is-unicode/</link>
		<comments>http://pascaldevink.wordpress.com/2009/10/15/the-hell-that-is-unicode/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 09:49:53 +0000</pubDate>
		<dc:creator>pascaldevink</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://pascaldevink.wordpress.com/?p=5</guid>
		<description><![CDATA[In the project I&#8217;m currently working on, I need to help a client move his web-application to a new country, or rather copy the application as they extend their business. The project was setup and the application was moved to the cloud to also respond to their current performance problems. Some fixes were done and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=5&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the project I&#8217;m currently working on, I need to help a client move his web-application to a new country, or rather copy the application as they extend their business. The project was setup and the application was moved to the cloud to also respond to their current performance problems. Some fixes were done and some functionality was added. The first version was put live 2 months ago and slowly, new users are signing up for their service.<br />
<span id="more-5"></span><br />
As was to be expected, the new users find some bugs now and then, which were all easy to fix, until now&#8230;<br />
Today we received an email from a user, stating that it was impossible to use special characters in usernames, such as the infamous ß (double &#8216;s&#8217; in German) and others. I immediately thought of a unicode issue, and since the problem was obviously the database, I fired up phpMyAdmin to conduct some tests.</p>
<p>My tests confirmed what the user reported and I quickly saw that the table was setup as a &#8216;latin1_swedish_ci&#8217; collection (why Swedish is beyond me). I changed this to &#8216;utf8_general_ci&#8217; and restarted my tests, expecting a fix. Experienced users in this field already know: it didn&#8217;t work. Even changing the individual column collections from &#8216;latin1_swedish_ci&#8217; to &#8216;utf8_general_ci&#8217; didn&#8217;t help. There seemed to be a mismatch between the unicode the database used and the unicode the application was using.</p>
<p>A quick google search let me to the <a title="MySQL docs about unicode support" href="http://dev.mysql.com/doc/refman/5.0/en/charset-unicode.html" target="_blank">MySQL docs</a> and pointed me into the right direction. The fix was to explicitly set the client character set after making a connection, but before any query was done.<br />
Ultimately, the code looked like this:<br />
<code><br />
mysql_connect( $this-&gt;m_host, $this-&gt;m_mysqluser, $this-&gt;m_mysqlpassword ) or die("Could not connect to MySQL database");<br />
mysql_select_db($this-&gt;m_db);<br />
mysql_query("SET NAMES utf8");<br />
</code><br />
Althoughthis works perfectly, this doesn&#8217;t seem like a clean solution though. So if there is anybody out there with a better solution, don&#8217;t hesitate to leave a comment.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pascaldevink.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pascaldevink.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pascaldevink.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pascaldevink.wordpress.com&amp;blog=9948854&amp;post=5&amp;subd=pascaldevink&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://pascaldevink.wordpress.com/2009/10/15/the-hell-that-is-unicode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/15bd509601f2b058f9d6edf45302dff0?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">pascaldevink</media:title>
		</media:content>
	</item>
	</channel>
</rss>
