<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>PHP on the beach - zend</title>
    <link>http://www.phponthebeach.net/</link>
    <description>The place where PHP is sunnier, breezier, saltier and a little sandy...</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.4.1 - http://www.s9y.org/</generator>
    
    

<item>
    <title>Caching made simple with Zend_Cache</title>
    <link>http://www.phponthebeach.net/archives/4-Caching-made-simple-with-Zend_Cache.html</link>
            <category>cache</category>
            <category>framework</category>
            <category>PHP</category>
            <category>zend</category>
    
    <comments>http://www.phponthebeach.net/archives/4-Caching-made-simple-with-Zend_Cache.html#comments</comments>
    <wfw:comment>http://www.phponthebeach.net/wfwcomment.php?cid=4</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.phponthebeach.net/rss.php?version=2.0&amp;type=comments&amp;cid=4</wfw:commentRss>
    

    <author>nospam@example.com (Jordi Roura)</author>
    <content:encoded>
    &lt;p&gt;One of the nice things about the Zend Framework is that most of its libraries can be used either from within the framework or as stadalone bits of code which can be seamlessly integrated into non-Zend applications.&amp;#160; Zend_Cache is no exception and can be used to quickly apply caching solutions to common performance problems.&amp;#160; If you are new to caching, or wondering what caching is, it is simply a technique by which something is stored to avoid running the same code over and over again.&amp;#160; For example, if you have a query that is going to be launched time and time again and the result is not going to vary, we can &lt;em&gt;cache&lt;/em&gt; it and run it only once, retrieving the cached result until the cache expires thus saving the database a lot of stress.&lt;br /&gt;&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;The hardest part to understand about Zend_Cache is its collection of &lt;em&gt;frontends&lt;/em&gt; and &lt;em&gt;backends&lt;/em&gt;.&amp;#160; Since the aim of this article is to provide an introduction into quickly deploying a caching solution I will not cover all the options, but they are perfectly covered in the &lt;a title=&quot;Zend_Cache documentation&quot; target=&quot;_blank&quot; href=&quot;http://framework.zend.com/manual/en/zend.cache.html&quot;&gt;Zend_Cache framework documentation&lt;/a&gt;.&amp;#160; However, once we go past the tricky names we can see that a &lt;em&gt;frontend&lt;/em&gt; is merely a way to specify &lt;em&gt;&lt;strong&gt;what&lt;/strong&gt;&lt;/em&gt; we want to store in cache, and a &lt;em&gt;backend&lt;/em&gt; they to specify &lt;strong&gt;&lt;em&gt;how&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;Zend_Cache can store virtually anything from php objects to pages or functions and, out of the box, supports storage &amp;quot;mediums&amp;quot; such as filesystem, Sqlite, Memcache or Apc among many others.&amp;#160; Again, the documentation provides full reference, but for the purpose of this tutorial we will concentrate on the Core frontend (a generic container of text) and the File backend.&amp;#160; Why?&amp;#160; Because it is the most widely available solution and a good way to get started with Zend_Cache.&amp;#160; If you are interested in other options please comment and I will address them.&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;Now let&#039;s see a simple instantiation of a cache object:&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;&lt;font face=&quot;courier new,courier,monospace&quot;&gt;$frontendOptions = array(&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &#039;lifetime&#039; =&amp;gt; 3600, // cache lifetime of 1 hour&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &#039;automatic_serialization&#039; =&amp;gt; true&lt;br /&gt;);&lt;br /&gt;$backendOptions = array();&lt;br /&gt;&lt;br /&gt;$cache = Zend_Cache::factory(&#039;Core&#039;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &#039;File&#039;,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $frontendOptions,&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $backendOptions);&lt;/font&gt;&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;Let&#039;s take a look at what we&#039;ve done.&amp;#160; First, we&#039;ve defined the option values that will define the behavior of the frontend.&amp;#160; In this case we&#039;ve given the cached items a lifespan of one hour and we&#039;ve set the automatic serialization option to true which guarantees the Core frontend becomes a pretty safe container of virtually anything.&amp;#160; Secondly, we&#039;ve defined the option values for the backend.&amp;#160; In this case I&#039;ve left it empty since default values are the most generic and work fairly well.&amp;#160; Otherwise, we can change where the files containing the objects are stored, whether they should be locked, whether there should be read control etc...&amp;#160; And finally we create the cache object using the Zend_Cache factory method.&amp;#160; Voilà!&amp;#160; Now let&#039;s take a peek on how it&#039;s used:&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;&lt;font face=&quot;courier new,courier,monospace&quot;&gt;if (!$obj = $cache-&amp;gt;load(&#039;Object_Expensive_To_Generate&#039;)) {&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $obj = new ObjectThatIsExpensiveToGenerate();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $obj-&amp;gt;overloadDatabaseWithExpensiveQueries();&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $obj-&amp;gt;hogTheCpu();&lt;br /&gt;&lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $cache-&amp;gt;save($obj, &#039;Object_Expensive_To_Generate&#039;);&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;Woohoo!&amp;#160; Now we only get to go through the painful process of generating an ObjectThatIsExpensiveToGenerate once an hour.&amp;#160; Now let&#039;s take a peek at what we&#039;ve done...&amp;#160; If the object has not yet been cached, or it has expired, the condition in the if clause will return true, and hence start generating and instance of the object.&amp;#160; However, if it has been cached it will skip the if altogether and leave us with a perfectly functional $obj at the other side without going through all the hassle and thus saving valuable resources.&amp;#160; If we do enter the conditional though, the last thing we do is to put the object in cache so we can safely retrieve it for the next hour.&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;And now that we&#039;ve finished this brief introduction into Zend_Cache and caching in general, it&#039;s time to apply it or to delve deeper and explore what this powerful class has to offer!&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Sun, 11 Apr 2010 20:42:22 -0500</pubDate>
    <guid isPermaLink="false">http://www.phponthebeach.net/archives/4-guid.html</guid>
    
</item>
<item>
    <title>How to log into a Google Analytics account with PHP</title>
    <link>http://www.phponthebeach.net/archives/3-How-to-log-into-a-Google-Analytics-account-with-PHP.html</link>
            <category>framework</category>
            <category>PHP</category>
            <category>zend</category>
    
    <comments>http://www.phponthebeach.net/archives/3-How-to-log-into-a-Google-Analytics-account-with-PHP.html#comments</comments>
    <wfw:comment>http://www.phponthebeach.net/wfwcomment.php?cid=3</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://www.phponthebeach.net/rss.php?version=2.0&amp;type=comments&amp;cid=3</wfw:commentRss>
    

    <author>nospam@example.com (Jordi Roura)</author>
    <content:encoded>
    &lt;p&gt;The first step in using the Google Analytics API to retrieve insightful data into your PHP application is logging in.&amp;#160; To this end we will use &lt;a title=&quot;The Zend Framework&quot; target=&quot;_blank&quot; href=&quot;http://framework.zend.com&quot;&gt;Zend Framework&lt;/a&gt;&#039;s Gdata libraries which get rid of much of the hassle by providing a comprehensive set of classes and functions that cover most of the GA API needs. The mechanism is simple: you boot up a connection client, use it to open a feed and use that feed to retrieve the necessary reports from GA.&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;&lt;font face=&quot;courier new,courier,monospace&quot;&gt;$email = &#039;some@email.com&#039;;&amp;#160;&amp;#160;&amp;#160; // The email that identifies the Google Analytics Account&lt;br /&gt;$password = &#039;xXxXxXxXx&#039;;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; // The Google Analytics account&#039;s password&lt;br /&gt;&lt;br /&gt;$client = Zend_Gdata_ClientLogin::getHttpClient($email,$password, &#039;analytics&#039;, null, &#039;curl-accountFeed-v2&#039;, null, null, &#039;https://www.google.com/accounts/ClientLogin&#039;, &#039;GOOGLE&#039;);&lt;br /&gt;$feed = new Zend_Gdata_Gapps($client);&lt;br /&gt;$response = $feed-&amp;gt;get(&#039;https://www.google.com/analytics/feeds/data?ids=ga:13962678&amp;amp;dimensions=ga:browser&amp;amp;metrics=ga:pageviews&amp;amp;filters=ga:browser%3D~%5EFirefox&amp;amp;start-date=2009-01-01&amp;amp;end-date=2009-12-31&#039;);&lt;br /&gt;$xml = $response-&amp;gt;getBody();&lt;/font&gt;&lt;/p&gt; &lt;br /&gt;
&lt;p&gt;And now, in the &lt;font face=&quot;courier new,courier,monospace&quot;&gt;$xml&lt;/font&gt; variable holds the raw XML with the data from the report so you can collect it and use it in your app!&lt;br /&gt;&lt;/p&gt; 
    </content:encoded>

    <pubDate>Fri, 22 Jan 2010 15:11:28 -0600</pubDate>
    <guid isPermaLink="false">http://www.phponthebeach.net/archives/3-guid.html</guid>
    
</item>

</channel>
</rss>