<?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>Fri, 21 May 2010 14:12:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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;">
$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;">
$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;">
//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>2</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[PHP]]></category>
		<category><![CDATA[iPhone]]></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[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;">
$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;">
$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>11</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;">
$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;">
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>1</slash:comments>
		</item>
	</channel>
</rss>
