<?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/"
	>

<channel>
	<title>Jonathan Cremin &#187; php</title>
	<atom:link href="http://crem.in/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://crem.in</link>
	<description>Not&#160;designed&#160;for&#160;Internet&#160;Explorer</description>
	<lastBuildDate>Mon, 10 May 2010 11:34:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP caching and APC</title>
		<link>http://crem.in/2009/10/09/php-caching-and-apc/</link>
		<comments>http://crem.in/2009/10/09/php-caching-and-apc/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 20:34:21 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://crem.in/?p=305</guid>
		<description><![CDATA[A friend asked me recently about the caching options available to him with PHP on a linux stack. While he had looked into memcached and seen the difference it can make, he had overlooked APC. APC, or Alternative PHP Cache, not only allows for faster pages through opcode caching, but also since v3.0.0, allows for [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>A friend asked me recently about the caching options available to him with PHP on a linux stack. While he had looked into memcached and seen the difference it can make, he had overlooked APC.</p>
<p>APC, or Alternative PHP Cache, not only allows for faster pages through opcode caching, but also since v3.0.0, allows for users to store any kind of data in memory for access between and across all requests. See my example below for a better idea on how to use it.</p>
<pre><code>/* The first argument is the unique key which
 you will use to store some data later.
For globally cached data, the URL could make a good key,
and you could append the user id for user specific data.
The second argument is set to true or false depending
on whether APC finds data at the location,
if we don't find it, we know we need
to (re)generate it. */

$html = apc_fetch("unique_key_url", $success);
if(!$success)
{
	$html = big_and_slow_function();

	/*here the first argument is the key again,
	followed by the data to store and
	finally the time to live period in seconds */

	apc_add("unique_key_url", $html, 180);
}
echo $html;
</code></pre>
<p>Using a mechanism like this, you can see massive decreases in page load times. The friend I mentioned earlier brought his front page load time down from a number of seconds to low milliseconds.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2009/10/09/php-caching-and-apc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and stdClass</title>
		<link>http://crem.in/2009/06/28/php-and-stdclass/</link>
		<comments>http://crem.in/2009/06/28/php-and-stdclass/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 23:44:09 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://crem.in/?p=279</guid>
		<description><![CDATA[The built in class stdClass can be instantiated manually for creating generic objects which you can then set member variables for, this is useful for passing objects to other functions or methods which expect to take an object as an argument. An even more likely usage is casting an array to an object which takes [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The built in class stdClass can be instantiated manually for creating generic objects which you can then set member variables for, this is useful for passing objects to other functions or methods which expect to take an object as an argument. An even more likely usage is casting an array to an object which takes each value in the array and adds it as a member variable with the name based on the key in the array.</p>
<p><code>&lt;?php<br />
$obj = (object) array("foo" => "bar")<br />
echo $obj->foo; // outputs "bar"<br />
?&gt;<br />
</code></p>
<p>One place you might get caught out here is trying to directly access numerically indexed values on the object, this breaks PHP&#8217;s naming convention and does not work correctly even with escaping.</p>
<p><code>&lt;?php<br />
$obj = (object) array("foo"=>"bar","foobar");<br />
echo $obj->foo; //outputs "bar"<br />
echo $obj->{0}; //$x->0 would cause a syntax error, this simply causes a notice for being unable to find the variable.<br />
</code></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2009/06/28/php-and-stdclass/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HTTP Auth with PHP</title>
		<link>http://crem.in/2009/06/27/http-auth-with-php/</link>
		<comments>http://crem.in/2009/06/27/http-auth-with-php/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 17:37:23 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://crem.in/?p=150</guid>
		<description><![CDATA[HTTP Auth has a number of practical uses even in complex PHP backed systems. A prime example, and the reason I had looked into it, is web service and API authentication. In this case it is much simpler for the client to provide the details in this manner rather than perform an extra request to [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>HTTP Auth has a number of practical uses even in complex PHP backed systems. A prime example, and the reason I had looked into it, is web service and API authentication. In this case it is much simpler for the client to provide the details in this manner rather than perform an extra request to grab an authorisation token. A basic example lifted from the PHP manual is below.</p>
<pre><code>&lt;?php
if (!isset($_SERVER['PHP_AUTH_USER'])) {
&nbsp;&nbsp;&nbsp;&nbsp;header('WWW-Authenticate: Basic realm="My Realm"');
&nbsp;&nbsp;&nbsp;&nbsp;header('HTTP/1.0 401 Unauthorized');
&nbsp;&nbsp;&nbsp;&nbsp;echo 'Text to send if user hits Cancel button';
&nbsp;&nbsp;&nbsp;&nbsp;exit;
} else {
&nbsp;&nbsp;&nbsp;&nbsp;echo "&lt;p&gt;Hello {$_SERVER['PHP_AUTH_USER']}.&lt;/p&gt;";
&nbsp;&nbsp;&nbsp;&nbsp;echo "&lt;p&gt;You entered {$_SERVER['PHP_AUTH_PW']} as your password.&lt;/p&gt;";
}
?&gt;</code></pre>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2009/06/27/http-auth-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AIB and Three Webtext PHP5 APIs</title>
		<link>http://crem.in/2009/06/15/aib-and-three-webtext-php5-apis/</link>
		<comments>http://crem.in/2009/06/15/aib-and-three-webtext-php5-apis/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 00:37:38 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[aib]]></category>
		<category><![CDATA[three]]></category>
		<category><![CDATA[webtext]]></category>

		<guid isPermaLink="false">http://jonathancremin.com/?p=241</guid>
		<description><![CDATA[Over the last day I&#8217;ve put together two PHP5 API classes (loosely termed, it&#8217;s screen scraping at heart) for online services I use, AIB online banking and Three&#8217;s newly launched webtexts. I&#8217;m releasing both under the LGPL license and you can find them in my open source releases directory. Update: I&#8217;ve ported the Three API [...]


Related posts:<ol><li><a href='http://crem.in/2009/06/17/three-web-text-widget/' rel='bookmark' title='Permanent Link: Three Web Text Widget'>Three Web Text Widget</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Over the last day I&#8217;ve put together two PHP5 API classes (loosely termed, it&#8217;s screen scraping at heart) for online services I use, AIB online banking and Three&#8217;s newly launched webtexts. I&#8217;m releasing both under the LGPL license and you can find them in my <a href="http://crem.in/releases">open source releases</a> directory.</p>
<p><em>Update: I&#8217;ve ported the Three API to Perl and added it to the three releases directory</em></p>


<p>Related posts:<ol><li><a href='http://crem.in/2009/06/17/three-web-text-widget/' rel='bookmark' title='Permanent Link: Three Web Text Widget'>Three Web Text Widget</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2009/06/15/aib-and-three-webtext-php5-apis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Amazon S3 for backups</title>
		<link>http://crem.in/2008/08/06/using-amazon-s3-for-backups/</link>
		<comments>http://crem.in/2008/08/06/using-amazon-s3-for-backups/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 11:42:18 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[archive]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[cloud storage]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://crem.in/?p=34</guid>
		<description><![CDATA[It became clear early on in the planning stages of our current project that we were going to need a reliable backup solution. We discussed backing up to another server we already have in the datacenter and backing up to a server in another datacenter. The former was not redundant enough for our liking and [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>It became clear early on in the planning stages of our current project that we were going to need a reliable backup solution. We discussed backing up to another server we already have in the datacenter and backing up to a server in another datacenter. The former was not redundant enough for our liking and the latter would introduce extra costs we could do without so early on.</p>
<p>Enter <a href="http://aws.amazon.com/s3">Amazon S3</a>. You pay for as little as you need and it expands as you do. The S3 docs point to <a href="http://undesigned.org.za/2007/10/22/amazon-s3-php-class">undesigned&#8217;s</a> PHP5 library using cURL. Perfect. 15 minutes and about 10 lines of code later we were archiving and backing up user content to S3.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2008/08/06/using-amazon-s3-for-backups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reloading Apache from within PHP</title>
		<link>http://crem.in/2008/08/01/reloading-apache-from-within-php/</link>
		<comments>http://crem.in/2008/08/01/reloading-apache-from-within-php/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 09:49:26 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[redhat]]></category>
		<category><![CDATA[reload]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[sudoers]]></category>

		<guid isPermaLink="false">http://crem.in/?p=19</guid>
		<description><![CDATA[&#60;?php exec('echo "/usr/bin/sudo /etc/init.d/httpd reload" &#124; /usr/bin/at now'); ?&#62; There&#8217;s a couple of steps to follow to get the above code working as Apache runs on port 80, which requires root priviliges to access. These steps are for Redhat/Centos (tested on Centos 5), but can easily be modified for any distro. You should avoid restarting [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<pre class="code">
&lt;?php
exec('echo "/usr/bin/sudo /etc/init.d/httpd reload" | /usr/bin/at now');
?&gt;
</pre>
<p></p>
<p>There&#8217;s a couple of steps to follow to get the above code working as Apache runs on port 80, which requires root priviliges to access. These steps are for Redhat/Centos (tested on Centos 5), but can easily be modified for any distro. You should avoid restarting if at all possible. If you absolutely have to, just replace &#8220;reload&#8221; with &#8220;restart&#8221; in the instructions below.</p>
<ul>
<li>Edit your sudoers file and add the following line ( If you are using suPHP/suexec you&#8217;ll need to change apache below to your web user ):<br />
<code>apache ALL= NOPASSWD: /etc/init.d/httpd reload</code>
</li>
<li>
Comment out the following line in your sudoers file<br />
<code>Defaults requiretty</code>
</li>
<li>
Add the web user to /etc/at.allow to give it access to &#8216;at&#8217;.
</li>
</ul>
<p>That&#8217;s it, you should now be able to reload Apache from within PHP using the code segment provided.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2008/08/01/reloading-apache-from-within-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FancyUpload 2.0</title>
		<link>http://crem.in/2008/05/12/fancyupload-20/</link>
		<comments>http://crem.in/2008/05/12/fancyupload-20/#comments</comments>
		<pubDate>Mon, 12 May 2008 14:18:24 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[www]]></category>
		<category><![CDATA[fancyupload]]></category>
		<category><![CDATA[growl]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[localhostr]]></category>
		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://crem.in/?p=17</guid>
		<description><![CDATA[Digitarald has updated his FancyUpload script to version 2. I used his first version as the uploader on localhostr and I think I might just update it to use this one. With the original I had to hack together some json support but it seems this is the default behaviour of the latest release. I [...]


Related posts:<ol><li><a href='http://crem.in/2008/04/28/neowindex-2008/' rel='bookmark' title='Permanent Link: Neowindex 2008'>Neowindex 2008</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://digitarald.de">Digitarald</a> has updated his <a href="http://digitarald.de/project/fancyupload/">FancyUpload</a> script to version 2. I used his first version as the uploader on localhostr and I think I might just update it to use this one.</p>
<p>With the original I had to hack together some json support but it seems this is the default behaviour of the latest release. I love this guy&#8217;s work and you should check out the <a href="http://digitarald.de/projects/">other projects</a> he has, all of which are built on the fantastic <a href="http://mootools.net">mootools</a>. I particularly like <a href="http://digitarald.de/project/roar/">Roar</a> notifications which is inspired by Growl, the notification system for Mac OS X.</p>


<p>Related posts:<ol><li><a href='http://crem.in/2008/04/28/neowindex-2008/' rel='bookmark' title='Permanent Link: Neowindex 2008'>Neowindex 2008</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2008/05/12/fancyupload-20/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Autoloading Objects</title>
		<link>http://crem.in/2008/02/28/php-autoloading-objects/</link>
		<comments>http://crem.in/2008/02/28/php-autoloading-objects/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 16:22:10 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[autoload]]></category>
		<category><![CDATA[code example]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://crem.in/2008/02/28/php-autoloading-objects/</guid>
		<description><![CDATA[Having only No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Having only</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://crem.in/2008/02/28/php-autoloading-objects/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
