<?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>Julian Castaneda &#187; PHP</title>
	<atom:link href="http://www.smooka.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.smooka.com/blog</link>
	<description>From programming to music!</description>
	<lastBuildDate>Mon, 29 Aug 2011 15:50:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>UTF-8 Encoding problems with file_get_contents() and DOMDocument</title>
		<link>http://www.smooka.com/blog/2011/08/29/utf-8-encoding-file_get_contents-and-domt/</link>
		<comments>http://www.smooka.com/blog/2011/08/29/utf-8-encoding-file_get_contents-and-domt/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 15:50:40 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=447</guid>
		<description><![CDATA[I recently bumped into an encoding issue on a project I was working on. I was trying to scrape some content off a website that had ISO-8859-1 [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bumped into an encoding issue on a project I was working on.<br />
I was trying to scrape some content off a website that had ISO-8859-1 charset encoding, and I needed to capture some text and store it in a database as UTF-8.</p>
<p>After some trial and error I discovered a way to properly change the encoding before saving it in the DB.</p>
<p>A simplified version of what I did:</p>
<pre class="brush: php; title: ; notranslate">
 $url = 'http://www.smooka.com/blog/';
 $html = file_get_contents($url);

 //Change encoding to UTF-8 from ISO-8859-1
 $html = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $html);
</pre>
<p><span id="more-447"></span><br />
This partially solved my problem. But for some reason single quotes where displayed with a question mark symbol. After reading documentation, forums, etc.. I discovered that I needed to translate ASCII characters. </p>
<pre class="brush: php; title: ; notranslate">
 $dom = new Zend_Dom_Query($html);
 $results = $dom-&gt;query('div p');

 foreach ($results as $result)
 {
    $line = $result-&gt;nodeValue;
    $line = iconv('UTF-8', 'ASCII//TRANSLIT', $line);
 }
</pre>
<p>Hope this saves you some time, as I was not able to find a complete solution on the web so I had to piece everything together.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2011/08/29/utf-8-encoding-file_get_contents-and-domt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: Change UTC time to local time</title>
		<link>http://www.smooka.com/blog/2011/06/03/utc-time-to-local-time/</link>
		<comments>http://www.smooka.com/blog/2011/06/03/utc-time-to-local-time/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 21:10:30 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[utc]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=439</guid>
		<description><![CDATA[Did you know that you can quickly change UTC time stamps to Local time by doing the following: It&#8217;s so obvious, but I only wished, I knew [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that you can quickly change UTC time stamps to Local time by doing the following:</p>
<pre class="brush: php; title: ; notranslate">
//make sure your time is set
date_default_timezone_set('America/New_York');

$datetime = '2004-02-12T15:19:21+00:00';

//convert the given datetime string to time
$newDatetime = strtotime($datetime);

//re-contruct to format
$newDatetime = date('Y-m-d H:i:s', newDatetime);
</pre>
<p>It&#8217;s so obvious, but I only wished, I knew this before trying all sort of crazy stuff. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2011/06/03/utc-time-to-local-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit Testing your AJAX requests with Zend Framework and PHPunit</title>
		<link>http://www.smooka.com/blog/2011/01/15/unit-testing-ajax-requests-zend-framework-phpunit/</link>
		<comments>http://www.smooka.com/blog/2011/01/15/unit-testing-ajax-requests-zend-framework-phpunit/#comments</comments>
		<pubDate>Sat, 15 Jan 2011 20:28:26 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[Frameworks and API's]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[PHPunit]]></category>
		<category><![CDATA[unit test]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=421</guid>
		<description><![CDATA[I ran into a problem yesterday, when trying to create a couple of unit tests using PHPunit along side the Zend Framework. If you want to unit [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.smooka.com/blog/wp-content/uploads/phpunit.gif" alt="" title="phpunit" width="94" height="80" class="alignleft size-full wp-image-432" />I ran into a problem yesterday, when trying to create a couple of unit tests using <a href="https://github.com/sebastianbergmann/phpunit/" target="_blank">PHPunit</a> along side the <a href="http://zendframework.com/" target="_blank">Zend Framework</a>. </p>
<p>If you want to unit test an action in a controller that checks the request to see if is an XML HTTP Request using the <a href="http://www.smooka.com/blog/2009/04/17/5-things-working-with-zend-framework-and-ajax/">isXmlHttpRequest()</a> method provided by the Zend Framework, then you will definitely run into a problem.</p>
<p>isXmlHttpRequest() pretty much checks to see if the $_SERVER['HTTP_X_REQUESTED_WITH'] is set with &#8216;XMLHttpRequest&#8217;, if not, then returns FALSE. I thought that by setting the server variable with XMLHttpRequest directly will allow me to bypass the check.<br />
<span id="more-421"></span></p>
<pre class="brush: php; title: ; notranslate">
function myAjaxTestAction()
{
      $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';

      //then do your ajax tests here
}
</pre>
<p>This solution seemed like it was going to work, but it turns out that isXmlHttpRequest() makes a call to getHeader() like this:</p>
<pre class="brush: php; title: ; notranslate">
public function isXmlHttpRequest()
{
        return ($this-&gt;getHeader('X_REQUESTED_WITH') == 'XMLHttpRequest');
}
</pre>
<p>What I didn&#8217;t know is that when you are doing unit tests the framework extends the HTTP class and changes the getHeader() to only use headers set using the setHeader or setHeaders methods.<br />
After a couple of minutes tracing over the calls being made. I discovered that the fix was pretty simple, set our headers doing the following in your test case:</p>
<pre class="brush: php; title: ; notranslate">
function myAjaxTestAction()
{
      $this-&gt;request-&gt;setHeader('X_REQUESTED_WITH');

      //then do your ajax tests here
}
</pre>
<p>This will fake an AJAX request and return the expected result.</p>
<p>I hope this article helps many of you since I spent many hours trying to decipher why setting &#8216;XMLHttpRequest&#8217; to the $_SERVER did not work as I expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2011/01/15/unit-testing-ajax-requests-zend-framework-phpunit/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Internalization and Translation</title>
		<link>http://www.smooka.com/blog/2010/08/06/zend-framework-translation-internalization/</link>
		<comments>http://www.smooka.com/blog/2010/08/06/zend-framework-translation-internalization/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 20:08:12 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[Frameworks and API's]]></category>
		<category><![CDATA[How To]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[gettext]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Translate]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=362</guid>
		<description><![CDATA[This week I set myself to lay the ground work of translation on the application we are doing at work. In our application we are using Zend [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.smooka.com/blog/wp-content/uploads/translate1.png" alt="" title="translate" width="200" height="259" class="alignright size-full wp-image-377" />This week I set myself to lay the ground work of translation on the application we are doing at work. In our application we are using Zend Framework, so I decided to take a look into the Zend_Translate component to see if it was easy and something that could work in our current environment.</p>
<p>After reading the reference guide on <a href="http://framework.zend.com/manual/en/zend.translate.html" target="_blank">Zend_Translate</a> I decided that we were going to use &#8220;<a href="http://www.gnu.org/software/gettext/manual/gettext.html" target="_blank">gettext</a>&#8221; as our translation adapter.  PHP has support for gettext right our of the box, and with the Zend_Translate it&#8217;s easy to change adapters, if you decide that you want to use a different adapter.</p>
<p>Assuming that you already have the latest version of Zend Framework (1.10.*) installed in your server, I&#8217;m going to explain and guide you guys on how I got it all working.<br />
<span id="more-362"></span></p>
<p>First you need to get a tool that we will use to parse your project files to create the translation dictionaries. I&#8217;m using <a href="http://www.poedit.net/" target="_blank">PoEdit</a> which is free and supports multiple platforms.</p>
<p>Now let&#8217;s put some code down in your index.phtml file of you application. This one should be located in /yourapp/application/views/scripts/index/<br />
If it&#8217;s not there, then just create one, but make sure you have to corresponding controller and action.<br />
Inside of this file we are going to put the following:</p>
<pre class="brush: php; title: ; notranslate">

&lt;?php
$t = new Zend_Translate(
	'gettext',  //the adapter
	APPLICATION_PATH.'/translation', //where the lang files will be stored
	'auto',  //set to auto include .mo files
	array('scan' =&gt; Zend_Translate::LOCALE_FILENAME) //set to scan lang files
);

echo $t-&gt;_(&quot;This is my first translation&quot;).&quot;&lt;br/&gt;&quot;;
?&gt;
</pre>
<p>Before this piece of code works, we need to generate our translation files, else it will throw an error stating that the application can&#8217;t find the corresponding language files.</p>
<p>We need to create a new folder in your application folder. I&#8217;m calling it <strong>lang</strong>, but you can call it anything you want. This folder will be used to store your language files. So you should have something like &#8220;/yourapp/application/lang&#8221;.</p>
<p>After this, you need to open up PoEdit:</p>
<ol class="olblue">
<li>
<p>Go to File-&gt;Catalog Manager</p>
</li>
<li>
<p>Click on the &#8220;Create new translations project&#8221; icon</p>
</li>
<li>
<p>Give your project a name</p>
</li>
<li>
<p>Select the directory to store your translation files (&#8220;/yourapp/application/lang&#8221;) and hit OK</p>
</li>
</ol>
<p>With a newly crated project, we can now generate our language file.<br />
To do this,  close the Catalog Manager window</p>
<ol class="olblue">
<li>
<p>Go to File-&gt;New Catalog</p>
</li>
<li>
<p>Give it a project Name and/or version and be sure to feel in the appropriate information. Be sure to select Charset  &#8221;utf-8&#8243;</p>
</li>
<li>
<p>Now, click on the paths tab. Here you will have to add all the dir paths that point to the files that you want to parse for translation. (/yourapp/application/views/scripts/index/index.phtml)</p>
</li>
<li>
<p>Finally, click on the Keywords tab, and make sure you include the keyword the parser will use to identify the text that needs translation. In our example we will put an underscore &#8220;_&#8221;  since in our code we have echo $t-&gt;_(&#8220;This is my first translation&#8221;);</p>
</li>
<li>
<p>Hit OK and make sure that you save the file with a name such as mylang_en.po. The <strong>_en</strong> is crucial, since Zend_Translate will scan the appropriate language file and use this naming convention to load the appropriate file</p>
</li>
</ol>
<p>Since by default the PoEdit PHP parser handles files with .php extension. We need to modify the preferences so that it allows other types, such as .phtml files.<br />
To do this, go to Edit-&gt;Preferences-&gt;Parsers  When you get to parsers select PHP and then click on the EDIT button. In the parser setup window we need to add *.phtml extension to the &#8220;List of extensions&#8221; field in the Language section, separated by semicolons. The field should be something like this: <code>*.php;*.phtml</code><br />
Then, in the Invocation section, you need to add  -L php to the parser command. This should look like this  <code>xgettext --force-po -o %o %C %K %F -L php</code></p>
<p>Once you have completed this, a pop up screen will show the progress of the catalog update and then list you all the parsed strings. Hit OK and then you will be in the translation view. Just select the string you would like to translate save and you are good to go.</p>
<p>Once you&#8217;ve completed the following steps just copy the .po file and create additional one&#8217;s for the languages you want to do translation. Remember the naming convention discussed on the steps above.</p>
<p>In your code to switch languages, you need to put the following line <code>$t->setLocale('es');</code> This for example will switch the locale to Spanish and will try to load a file with &#8220;_es&#8221;</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$t = new Zend_Translate('gettext', APPLICATION_PATH.'/translation', 'auto', array('scan' =&gt; Zend_Translate::LOCALE_FILENAME));

echo $t-&gt;_(&quot;This is my first translation&quot;).&quot;&lt;br/&gt;&quot;;

//change locale to spanish
$t-&gt;setLocale('es');

echo $t-&gt;_(&quot;This is my Second translation&quot;).&quot;&lt;br/&gt;&quot;;
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2010/08/06/zend-framework-translation-internalization/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zend Framework and Firebug &#8211; Log and Debug your Projects</title>
		<link>http://www.smooka.com/blog/2009/08/21/zend-framework-firebug-log-debug/</link>
		<comments>http://www.smooka.com/blog/2009/08/21/zend-framework-firebug-log-debug/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 12:53:57 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[Frameworks and API's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[wildfire]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=162</guid>
		<description><![CDATA[When developing an application there are some important factors that you have to pay close attention to avoid problems in the future. I think one of the [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.smooka.com/blog/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/blog/wp-content/thumbnails/162.jpg&amp;w=70&amp;h=70&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p><img src="http://www.smooka.com/blog/wp-content/uploads/firebug.jpg" alt="firebug" title="firebug" width="162" height="162" class="alignleft size-full wp-image-167" />When developing an application there are some important factors that you have to pay close attention to avoid problems in the future. I think one of the most important is logging information on how your application is working and when it fails.</p>
<p>Must of us like to log only big exceptions and fatal errors, but the truth is, that when you are in the development process it&#8217;s very important to keep track of not just errors, but important information of when something gets executed. As a web developer one of the most important tools to have is <a href="http://getfirebug.com/">FireBug</a>. If you didn&#8217;t know, FireBug has an API that you can use to send console messages for logging purposes, when debugging JavaScript. But, did you know you can use FireBug to debug your php applications?<span id="more-162"></span></p>
<p>Through <a href="http://www.wildfirehq.org/">Wildfire</a>, a project that was created to help developers have a standard way for sending messages between different programming languages and scripts. The <a href="http://framework.zend.com/">Zend Framework</a> is now able to communicate to the Firebug console in order to display logging messages injected by PHP.</p>
<p>Using this component is pretty straight forward if you are using Zend_Controller_Front (MVC) with zend Framework.</p>
<p>Place this in your bootstrap file before dispatching your front controller</p>
<pre class="brush: php; title: ; notranslate">
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
</pre>
<p>Then whenever you want to log something to Firebug just use it in your model, view, or controller like this.</p>
<pre class="brush: php; title: ; notranslate">
$logger-&gt;log('This is an INFORMATIONAL log message!', Zend_Log::INFO);
$logger-&gt;log('This is a WARNING log message!', Zend_Log::WARN);
$logger-&gt;log('This is an ERROR log message!', Zend_Log::ERROR);
</pre>
<p>If you notice in the example above, you can specify the type of message you want to log (INFO, WARN, etc..). This is helpful when you want to clearly identify what type of message you are viewing since it will apply a special formatting and in some instances provide more information.</p>
<p>If you want to use the <a href="http://framework.zend.com/manual/en/zend.log.writers.html#zend.log.writers.firebug">Zend_Log_Writer_Firebug </a>as a stand alone here is the sample code you can use:</p>
<pre class="brush: php; title: ; notranslate">
//Instantiate the Firebug Writer
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);

//start the wildfire component
$request = new Zend_Controller_Request_Http();
$response = new Zend_Controller_Response_Http();
$channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
$channel-&gt;setRequest($request);
$channel-&gt;setResponse($response);

// Start output buffering
ob_start();

// Now you can make calls to the logger

$logger-&gt;log('This is a log message!', Zend_Log::INFO);

// Flush log data to browser
$channel-&gt;flush();
$response-&gt;sendHeaders();
</pre>
<p>If you don&#8217;t use ZendFramework there is another alternative to php developers. FirePhp, will also enable you to send log messages to Firebug by using php method calls. Be sure to check <a href="http://www.firephp.org/">FirePhp website</a> to get more information.</p>
<p>So remember that this is just one easy and great way to debug your projects, there are many other tools and methods you can incorporate into your projects. If you want to share other ways or simply just want to ask a question regarding this post, feel free to leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2009/08/21/zend-framework-firebug-log-debug/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Facebook iPhone App 3.0</title>
		<link>http://www.smooka.com/blog/2009/08/18/facebook-iphone-app-3-0/</link>
		<comments>http://www.smooka.com/blog/2009/08/18/facebook-iphone-app-3-0/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 20:32:27 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[Facebook]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=146</guid>
		<description><![CDATA[According to Joe Hewitt, developer of the facebook app. Version 3.0 of the facebook application has already been submitted to apple, and it&#8217;s waiting for approval. Here [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.smooka.com/blog/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/blog/wp-content/thumbnails/146.jpg&amp;w=70&amp;h=70&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>According to <a rel="nofollow" href="http://twitter.com/joehewitt">Joe Hewitt</a>, developer of the facebook app. Version 3.0 of the facebook application has already been submitted to apple, and it&#8217;s waiting for approval.<br />
<span id="more-146"></span><br />
<img class="alignleft size-medium wp-image-150" title="facebook 3.0" src="http://www.smooka.com/blog/wp-content/uploads/	6015_119271043379_6628568379_2445795_651735_n.jpg" alt="facebook 3.0" width="208" height="300" /></p>
<p><strong>Here is what&#8217;s new on the version of the app will contain:</strong></p>
<ul>
<li>New and improved Home screen that allows you to create shortcuts to your favorite friends and Pages</li>
<li>Events: the new events screen will allow you to see your upcoming Events and RSVP</li>
<li>Pages: support for pages was added so you can easily see and become fan of Pages and if you are a Page admin you can now post updates and photos to your pages.</li>
<li>Birthdays: see your friends&#8217; b-days.</li>
<li>Notes: now you can write Notes and read your friends&#8217; Notes</li>
<li>Complete photo management (create albums, delete albums, delete photos, delete photo tags, Upload photos to any album)</li>
<li>Upload videos from an iPhone 3GS</li>
<li>Change your Profile Picture</li>
<li>Zoom into photos</li>
<li>Like functionality was added so you can like posts and photos</li>
<li>See the same News Feed as the Facebook website</li>
<li>Visit links in a built-in web browser</li>
<li>See all of your friends&#8217; friends and Pages</li>
<li>See mutual friends</li>
<li>Easily search for people and Pages</li>
<li>Make friend requests</li>
<li>Quickly call or text your friends</li>
<li>Friends sorted by first or last name according to your settings</li>
<li>Chat friends sorted alphabeticaly</li>
</ul>
<p>There are a few missing functionality that we have been waiting for. But Joe Hewitt already mentioned in his twitter account that he already started development of version 3.1 of the facebook app and it will include &#8220;Push Notifications&#8221; and &#8220;Landscape Mode&#8221; and I guess he will throw in a few more small features.</p>
<p>Now with version 3.0 of the facebook application Will we ever need to go into the full facebook.com website? I guess that depends on how you use facebook, but, in my opinion I will be visiting the site less.</p>
<p><strong>Update: </strong> According to the developer of the application the update it&#8217;s live on the iPhone App Store. So go grab it and let us know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2009/08/18/facebook-iphone-app-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintaining PHP session when using CURL.</title>
		<link>http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-curl/</link>
		<comments>http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-curl/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 16:17:11 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=134</guid>
		<description><![CDATA[Working now on some iGoogle like dashboard for the system I&#8217;m developing. I was trying some stuff out with CURL and was having a hard time to [...]]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.smooka.com/blog/wp-content/plugins/simple-post-thumbnails/timthumb.php?src=/blog/wp-content/thumbnails/134.jpg&amp;w=70&amp;h=70&amp;zc=1&amp;ft=jpg' alt='post thumbnail' /></p>
<p>Working now on some iGoogle like dashboard for the system I&#8217;m developing.</p>
<p>I was trying some stuff out with CURL and was having a hard time to maintain my current session when making a curl request to another page. I needed to stay authenticated in order to retrieve my widget. </p>
<p>Here is my initial code:</p>
<pre class="brush: php; title: ; notranslate">
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';
$ch = curl_init($rssFeedLink);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
$response = curl_exec($ch);
curl_close($ch);
</pre>
<p>The problem with that piece of code is that it was generating a new session id instead of sending my current session.</p>
<p>The solution? <span id="more-134"></span> Put session_write_close() before you make the CURL request.</p>
<pre class="brush: php; title: ; notranslate">
$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/';

session_write_close();

$ch = curl_init($rssFeedLink);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );
$response = curl_exec($ch);
curl_close($ch);
</pre>
<p>What does session_write_close() do? It, ends the current session and store session data. Apparently, PHP does not like when multiple scripts play around with the session, so, it locks it. Putting session_write_close makes sure that your current session is stored so you can retrieve it and use it. </p>
<p>This little issue had my head spinning for a few hours, so, I hope this article helps you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2009/07/24/maintaining-php-session-when-using-curl/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Zend Cache and Zend Feed Problem</title>
		<link>http://www.smooka.com/blog/2009/04/22/zend-cache-and-zend-feed-problem/</link>
		<comments>http://www.smooka.com/blog/2009/04/22/zend-cache-and-zend-feed-problem/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 17:23:00 +0000</pubDate>
		<dc:creator>Julian</dc:creator>
				<category><![CDATA[Frameworks and API's]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Cache]]></category>
		<category><![CDATA[Zend_Feed]]></category>

		<guid isPermaLink="false">http://www.smooka.com/blog/?p=88</guid>
		<description><![CDATA[Today I ran into a problem while caching feeds using Zend_Cache. I decided that I wanted to cache the returned object by the Zend_Feed. 

While iterating through the feed, the script would output the following message "Warning: Invalid argument supplied for foreach()", under, "Zend/Feed/Element.php on line 322" on an empty cache.]]></description>
			<content:encoded><![CDATA[<p>Today I ran into a problem while caching feeds using Zend_Cache. I decided that I wanted to cache the returned object by the Zend_Feed. I had something like this:</p>
<pre class="brush: php; title: ; notranslate">
$rssFeedLink = 'http://www.smooka.com/blog/';
$cacheId = 'rss_feed';

$frontendOptions = array(
		   	'lifetime' =&gt; 1800, // cache lifetime of 30 mins
		   	'automatic_serialization' =&gt; true);

$backendOptions = array(
		    	// Directory where to put the cache files
		    	'cache_dir' =&gt; '/cache/'
			);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core','File', $frontendOptions, $backendOptions);

if (!$rss = $cache-&gt;load($cacheId)) {
	try {
		$rss = Zend_Feed::import($rssFeedLink);
	} catch (Exception $e) {
		$feedError = true;
	}

	//check to see if it did not fail
	if (!$feedError &amp;&amp; is_object($rss))
	{
		$cache-&gt;save($rss, $cacheId);
	}
}

//assuming that everything went right while fetching the feed
foreach ($rss as $item) {
	$channel['items'][] = array(
		'title'       =&gt; $item-&gt;title(),
		'link'        =&gt; $item-&gt;link(),
		'description' =&gt; $item-&gt;description()
	);
}
</pre>
<p><span id="more-88"></span><br />
While iterating through the feed, the script would output the following message &#8220;Warning: Invalid argument supplied for foreach()&#8221;, under, &#8220;Zend/Feed/Element.php on line 322&#8243; on an empty cache.</p>
<p>It appears that Zend_Feed and Zend_Cache do not get along, I&#8217;m pretty sure it&#8217;s a bug since it looks like Zend_Feed_Rss is sent to sleep by the $cache->save() call and it&#8217;s not waking up automatically. The solution that I found it&#8217;s pretty straight forward. Just modify the following piece of code.</p>
<pre class="brush: php; title: ; notranslate">
if (!$feedError &amp;&amp; is_object($rss))
{
	$cache-&gt;save($rss, $cacheId);
	//ADD a wakeup call to the RSS object
	$rss-&gt;__wakeup();
}
</pre>
<p>That should do the trick!</p>
<p>After I fixed the issue, I went back to the drawing board and decided that it was more efficient to cache the actual HTML output, instead of the returned object by Zend_Feed. That seems to work just fine, since the call to $cache->save() is done after the iteration of the feed items. That fixes the issue and at the same time you are eliminating the need to iterate and re-build the HTML every time the page is loaded.</p>
<p>Hope this information helps you, and if you have any questions or comments be sure to post them here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smooka.com/blog/2009/04/22/zend-cache-and-zend-feed-problem/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

