<?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>Cross-platform software &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/cross-platform-software/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP Strings Don&#8217;t Need Quotes</title>
		<link>/2012/04/26/php-strings-dont-need-quotes/</link>
		<comments>/2012/04/26/php-strings-dont-need-quotes/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:52:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[PHP interpreter]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Programming language]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Social Issues]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">/?p=3017</guid>
		<description><![CDATA[I bet you didn&#8217;t know that PHP strings don&#8217;t need quotes! Indeed PHP developers work with strings with either single or double quotes, but actually in some cases you don&#8217;t need them. PHP by Book Here&#8217;s how PHP developer declare a string, which is something very common in any programming language. $my_var = 'hello world'; &#8230; <a href="/2012/04/26/php-strings-dont-need-quotes/" class="more-link">Continue reading <span class="screen-reader-text">PHP Strings Don&#8217;t Need Quotes</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>I bet you didn&#8217;t know that PHP strings don&#8217;t need quotes! Indeed PHP developers work with strings with either single or double quotes, but actually in some cases you don&#8217;t need them.</p>
<h2>PHP by Book</h2>
<p>Here&#8217;s how PHP developer declare a string, which is something very common in any programming language.</p>
<pre lang="PHP">
$my_var = 'hello world';
// or
$my_var = "hello world";
</pre>
<h2>PHP Tricks</h2>
<p>What if you do the following:</p>
<pre lang="PHP">
echo hello;
</pre>
<p>That appears to be correct &#8230; Well, it&#8217;s not absolutely correct. You&#8217;ll be &#8220;noticed&#8221;.</p>
<pre lang="PHP">
// Notice: Use of undefined constant hello
echo hello;
</pre>
<p>However if you disable error reporting, the code will be completely fine.</p>
<pre lang="PHP">
error_reporting(0);

// no problem now
echo hello;
</pre>
<h2>Variations</h2>
<p>What follows from the thing above is that you can use strings without quotes:</p>
<pre lang="PHP">
// hello
echo hello;

// hello world (concatenated)
echo hello . ' world';

// helloworld
echo hello . world;
</pre>
<p>However you can&#8217;t have spaces and most of the &#8220;special&#8221; symbols.</p>
<pre lang="PHP">
// syntax error
echo hello world;

// syntax error
echo hello!;
</pre>
<h2>Final Words</h2>
<p>Although you can do this in PHP, that is completely wrong. The code becomes more difficult to read and understand. In the second place you can miss a $ sign in front of a variable declaration and thus the PHP interpreter will assume this is a string. So disable error reporting isn&#8217;t so great sometimes.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/06/10/json-and-zend-framework-zend_json/" rel="bookmark" title="JSON and Zend Framework? &#8211; Zend_Json">JSON and Zend Framework? &#8211; Zend_Json </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/04/26/php-strings-dont-need-quotes/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>How to Dump the Generated Zend_Db SQL Query</title>
		<link>/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/</link>
		<comments>/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 14:39:48 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[From]]></category>
		<category><![CDATA[Insert]]></category>
		<category><![CDATA[PHP programmer]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[select]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL keywords]]></category>

		<guid isPermaLink="false">/?p=2709</guid>
		<description><![CDATA[The Typical PHP Approach Typically a PHP programmer will write his SQL query as a string and will execute it via mysql_query. $sql = "SELECT * FROM my_table"; $resource = mysql_query($sql); So eventually when you want to dump this &#8220;complex&#8221; query, or whatever query there is, you can simply &#8220;echo&#8221; it and see what’s its &#8230; <a href="/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/" class="more-link">Continue reading <span class="screen-reader-text">How to Dump the Generated Zend_Db SQL Query</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/04/29/debugging-in-zend-framework/" rel="bookmark" title="Debugging in Zend Framework">Debugging in Zend Framework </a></li>
<li><a href="/2010/08/05/fetching-rows-with-zend_db-fetch/" rel="bookmark" title="Fetching Rows With Zend_Db fetch()">Fetching Rows With Zend_Db fetch() </a></li>
<li><a href="/2010/07/28/which-model-should-contain-that-method/" rel="bookmark" title="Which Model Should Contain That Method?">Which Model Should Contain That Method? </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>The Typical PHP Approach</h2>
<p>Typically a PHP programmer will write his SQL query as a string and will execute it via <a href="http://php.net/manual/en/function.mysql-query.php" title="PHP: mysql_query" target="_blank">mysql_query</a>.</p>
<pre lang="PHP">
$sql = "SELECT * FROM my_table";
$resource = mysql_query($sql);
</pre>
<p>So eventually when you want to dump this &#8220;complex&#8221; query, or whatever query there is, you can simply &#8220;echo&#8221; it and see what’s its syntax. </p>
<pre lang="PHP">
// this query is WRONG because of the where clause
$sql = "SELECT * FROM my_table WHERE id = ";

// dump and debug the wrong query
die($sql);

// this line won't be executed
$resource = mysql_query($sql);
</pre>
<p>So far so good, but things appear to be a bit different when you start to work with <a href="http://framework.zend.com/" title="Zend Framework" target="_blank">Zend Framework</a>. Higher levels of abstraction come with slightly more difficult ways to dump (debug) your SQL queries.</p>
<p>OK you&#8217;ve two options. Using <a href="http://framework.zend.com/manual/en/zend.db.select.html" title="Zend_Db_Select" target="_blank">Zend_Db_Select</a> or &#8230; not.<br />
<span id="more-2709"></span></p>
<h2>Dump Zend_Db_Select Query</h2>
<p>Debugging queries generated with Zend_Db_Select is as easy as the following snippet. Let’s say there’s a db table “users” and typically the model is called Users.</p>
<pre lang="PHP">
class Users extends Zend_Db_Table
{
	protected $_name = 'users';

	public function getSomeUsers()
	{
		$select = $this->select()
				->from(this->_name)
				->where('id > ');

		$rows = $this->fetchAll($select);
	}
}
</pre>
<p>Obviously this code is wrong, because the &#8220;where&#8221; clause is wrong and we don&#8217;t pass any values to it. So now the question is how can we dump this SQL. Well, since we use Zend_Db_Select, so the simplest way to dump the SQL is by calling __toString(). The code above will become as follows.</p>
<pre lang="PHP">
class Users extends Zend_Db_Table
{
	protected $_name = ‘users’;

	public function getSomeUsers()
	{
		$select = $this->select()
				->from(this->_name)
				->where('id > ');

		die($select->__toString());

		$rows = $this->fetchAll($select);
	}
}
</pre>
<p>That&#8217;s great, but how can we dump update/insert queries for instance?</p>
<h2>Dump with Zend_Db_Profiler</h2>
<p>The way you should dump insert or update queries is a bit different. You should use <a href="http://framework.zend.com/manual/en/zend.db.profiler.html" title="Zend_Db_Profiler" target="_blank">Zend_Db_Profiler</a>, which is a more complex way to debug (profile) your queries. You can not only debug insert or update queries, of course, but any queries generated by the Zend_Db abstraction. Let’s see how.</p>
<p>Now from a controller perspective this model can be just called as:</p>
<pre lang="PHP">
$users = new Users();
$users->update(array('name' => 'my name'), 'id =');
</pre>
<p>Obviously this code is wrong, again because of the where clause and now the question is how we can debug the generated SQL. The answer is: using Zend_Db_Profiler. Looking back again to the model, this should look like this.</p>
<pre lang="PHP">
class Users extends Zend_Db_Table
{
	protected $_name = ‘users’;

	public function updateSomeUsers()
	{
		// first enable the profiler
		$this->getProfiler()->setEnabled(true);

		// try to execute
		$this->update(array('name' => 'my name'), 'id = ');

		// dump the SQL
		Zend_Debug::dump($this->getProfiler()->getLastQueryProfile()->getQuery());

		// don't forget to disable the profiler is
		// you don't need it anymore
		$this->getProfiler()->setEnabled(false);
	}
}
</pre>
<p>The thing is that since Zend_Db is using prepared statements, the last row (the one with the Zend_Debug::&#8230;) will dump something like the following line.</p>
<pre lang="SQL">
UPDATE `users` SET `name` = ? WHERE (id =)
</pre>
<p>So as you can see, actually here you don’t see the name’s value, which should be “my name”. To see this you should call getQueryParams().</p>
<pre lang="PHP">
class Users extends Zend_Db_Table
{
	protected $_name = 'users';

	public function updateSomeUsers()
	{
		// first enable the profiler
		$this->getProfiler()->setEnabled(true);

		// try to execute
		$this->update(array('name' => 'my name'), 'id = ');

		// dump the SQL
		Zend_Debug::dump($this->getProfiler()->getLastQueryProfile()->getQuery());
		Zend_Debug::dump($this->getProfiler()->getLastQueryProfile()->getQueryParams());

		// don't forget to disable the profiler is
		// you don't need it anymore
		$this->getProfiler()->setEnabled(false);
</pre>
<p>Now the debug info will be something like this.</p>
<pre lang="PHP">
UPDATE `users` SET `name` = ? WHERE (id =)
array
	1 => string 'my name' (length 7)
</pre>
<p>Calling this from the controller there are some changes. Take a look at the example bellow.</p>
<pre lang="PHP">
$users = new Users();

// enable the profiler
$users->getAdapter()->getProfiler()->setEnabled(true);

// execute (or at least try to)
$users->update(array('name' => 'my name'), 'id =');

// debugdump the SQL
Zend_Debug::dump($users->getAdapter()->getProfiler()->getLastQueryProfile()->getQuery());
Zend_Debug::dump($users->getAdapter()->getProfiler()->getLastQueryProfile()->getQueryParams());

// don't forget to disable the profiler is
// you don't need it anymore
$users->getAdapter()->getProfiler()->setEnabled(false);
</pre>
<p>In this case you should use the longer model_name->getAdapter()</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/04/29/debugging-in-zend-framework/" rel="bookmark" title="Debugging in Zend Framework">Debugging in Zend Framework </a></li>
<li><a href="/2010/08/05/fetching-rows-with-zend_db-fetch/" rel="bookmark" title="Fetching Rows With Zend_Db fetch()">Fetching Rows With Zend_Db fetch() </a></li>
<li><a href="/2010/07/28/which-model-should-contain-that-method/" rel="bookmark" title="Which Model Should Contain That Method?">Which Model Should Contain That Method? </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/02/09/how-to-dump-the-generated-zend_db-sql-query/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A Memcached Zend_Cache</title>
		<link>/2011/01/17/a-memcached-zend_cache/</link>
		<comments>/2011/01/17/a-memcached-zend_cache/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 13:42:48 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Computer memory]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Memcached]]></category>
		<category><![CDATA[MMCache]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[ram]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Zend_Cache]]></category>

		<guid isPermaLink="false">/?p=2121</guid>
		<description><![CDATA[Zend_Cache Usually Zend_Cache is used to store cache files on the file system, which can be really fast and useful in most of the cases. However there&#8217;s a faster cache mechanism and hopefully it&#8217;s supported by Zend_Cache as well. This is the Memcached backend. A Faster Cache Memcached is a really powerful tool to cache &#8230; <a href="/2011/01/17/a-memcached-zend_cache/" class="more-link">Continue reading <span class="screen-reader-text">A Memcached Zend_Cache</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Zend_Cache</h2>
<p>Usually <a title="Zend_Cache" href="http://framework.zend.com/manual/en/zend.cache.html" target="_blank">Zend_Cache</a> is used to store cache files on the file system, which can be really fast and useful in most of the cases. However there&#8217;s a faster cache mechanism and hopefully it&#8217;s supported by Zend_Cache as well. This is the <a title="Memcached" href="http://memcached.org/" target="_blank">Memcached</a> backend.</p>
<h2>A Faster Cache</h2>
<p>Memcached is a really powerful tool to cache directly into the RAM. First, this tool has nothing to do primary with Zend Framework. It&#8217;s a server, usually started on some port, that can be called to store and get things from the memory. This of course is very fast, way faster than the cache in the hard drives.</p>
<h2>Zend_Cache and Memcached</h2>
<p>Zend_Cache has an interface to work with Memcached which is great as usual. The PHP example of Memcache (note that there are two things <a title="Memcache" href="http://php.net/manual/en/book.memcache.php" target="_blank">Memcache</a> and <a title="Memcached" href="http://memcached.org/" target="_blank">Memcached</a>, which are slight different) can be found here and as it says:</p>
<pre lang="php" escaped="true">
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
</pre>
<p>However this can be coded into a Zend Framework style like that:</p>
<pre lang="php">
$frontend = array('caching' => true, 'lifetime' => 1800, 'automatic_serialization' => true);

$backend = array(
    'servers' =>array(
        array('host' => '127.0.0.1', 'port' => 11211)
    ),
    'compression' => false
);

$cache = Zend_Cache::factory('Core', 'Memcached', $frontend, $backend);
</pre>
<p>Note that you don&#8217;t have the typical &#8220;cache_dir&#8221;, just because everything&#8217;s cached into the memory.</p>
<p>Now you can call the cache as it&#8217;s called with the &#8220;File&#8221; backend interface:</p>
<pre lang="php">
$key = 'mykey';

if (($result = $cache->load($key)) === false) {
	// call the slow database query here ...
	// save in $result
	
	$cache->save($result, $key);	
}

echo $result
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" rel="bookmark" title="How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/04/26/mysql-expressions-in-zend-framework/" rel="bookmark" title="MySQL Expressions in Zend Framework">MySQL Expressions in Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/01/17/a-memcached-zend_cache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Make MP4 Progressive with qt-faststart</title>
		<link>/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/</link>
		<comments>/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 11:11:31 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[Application software]]></category>
		<category><![CDATA[author]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Daniel G. Taylor]]></category>
		<category><![CDATA[FFmpeg]]></category>
		<category><![CDATA[Flash Video]]></category>
		<category><![CDATA[Free software]]></category>
		<category><![CDATA[main software]]></category>
		<category><![CDATA[MEncoder]]></category>
		<category><![CDATA[mobile device]]></category>
		<category><![CDATA[NDs-mPeG]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Qt]]></category>
		<category><![CDATA[qt-faststart]]></category>
		<category><![CDATA[qtfaststart.py]]></category>
		<category><![CDATA[reasonable solution]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[VLC media player]]></category>

		<guid isPermaLink="false">/?p=2027</guid>
		<description><![CDATA[A big part of the developers worldwide, who have dealt with video converting, sooner or later have been used FFMPEG. In fact I&#8217;d say that two of the main software on the video converting scene are FFMPEG and Mencoder. I began to use Mencoder back in 2005 and I used it as a DVD ripping &#8230; <a href="/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/" class="more-link">Continue reading <span class="screen-reader-text">How to Make MP4 Progressive with qt-faststart</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2011/01/27/few-thoughts-on-web-video/" rel="bookmark" title="Few Thoughts on Web Video">Few Thoughts on Web Video </a></li>
<li><a href="/2010/02/26/html5-video-support-detecting-playing-and-progressive-enhancement/" rel="bookmark" title="HTML5 video support. Detecting, playing and progressive enhancement!">HTML5 video support. Detecting, playing and progressive enhancement! </a></li>
<li><a href="/2010/10/26/ffmpeg-libx264-and-presets/" rel="bookmark" title="ffmpeg, libx264 and presets">ffmpeg, libx264 and presets </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>A big part of the developers worldwide, who have dealt with video converting, sooner or later have been used FFMPEG. In fact I&#8217;d say that two of the main software on the video converting scene are <a title="FFMPEG" href="http://www.ffmpeg.org/" target="_blank">FFMPEG</a> and <a title="Mencoder" href="http://www.mplayerhq.hu/DOCS/HTML/en/mencoder.html" target="_blank">Mencoder</a>. I began to use Mencoder back in 2005 and I used it as a DVD ripping tool, but my experience with it ends there, while now I use FFMPEG.</p>
<p>However FFMPEG is a converting program and many things depend on what kind of video files come as an input and what do you want to achieve as an output. Here comes the codec question, where various libraries can help. In my case, as I <a href="/2010/10/26/ffmpeg-libx264-and-presets/" target="_blank">wrote</a> few posts ago, I use MP4 as output encoded with h.264, both encoded with ffmpeg/libx264. So far so good, but there is one main problem that anyone used this pair knows.</p>
<h2>Flash Player and MP4</h2>
<p>As far as I know <a title="Flash Player" href="http://get.adobe.com/flashplayer/" target="_blank">Flash Player</a> 9 and beyond plays video files encoded with MP4/h.264 except the typical FLV (flash video files). This can help video sites not only to share their video content via web &#8211; within browser based flash players, but also to show them via some mobile device interface where MP4/h.264 is perhaps the only one reasonable solution. In this case the file is accessible in both medias.</p>
<p>By default Flash Player can play such FFMPEG encoded .mp4 files, but fist the whole file must be downloaded by the browser and only than the playback can begin. That&#8217;s because the FFMPEG puts meta info at the end of the video file, while the flash player needs it at the beginning and only than to begin playing while the file is still downloading.</p>
<h2>qt-faststart</h2>
<p>As the name of this <a title="qt-faststart" href="http://multimedia.cx/eggs/improving-qt-faststart/" target="_blank">software</a> says this program helps you move the important meta info from the end to the beginning of the file. This helps the video to playback as early as possible. In an ideal circumstances everything works just fine, but there is a serious problem in fact.</p>
<h2>qt-faststart and Server Crash</h2>
<p><a title="qt-faststart" href="http://multimedia.cx/eggs/improving-qt-faststart/" target="_blank">qt-faststart</a> is responsible to move the meta info where it must be &#8211; at the beginning of the video file, but cannot finish execution when the video file is broken or the meta info doesn&#8217;t exists. Actually this is not a problem of qt-faststart, but to the video file. However this was a critical problem in my case, because the video files remains stuck for hours of execution and 99% of CPU usage.</p>
<p>Thankfully there is a solution and it can be found in the qt-faststart wrapper &#8211; <a title="qtfaststart.py" href="https://github.com/danielgtaylor/qtfaststart" target="_blank">qtfaststart.py</a></p>
<h2>qtfaststart.py</h2>
<p>written on Python this script overcomes the disadvantages of qt-faststart. As described by his author Daniel G. Taylor:</p>
<ol>
<blockquote>
<li>Works everywhere Python can be installed</li>
<li>Handles both 32-bit (stco) and 64-bit (co64) atoms</li>
<li>Handles any file where the mdat atom is before the moov atom</li>
<li>Preserves the order of other atoms</li>
<li>Can replace the original file (if given no output file)</li>
</blockquote>
</ol>
<p>With its help not only qt-faststart doesn&#8217;t crash, but also the video files remain progressive as desired. The installation process is as difficult as copy/paste on the server where Python must be installed.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2011/01/27/few-thoughts-on-web-video/" rel="bookmark" title="Few Thoughts on Web Video">Few Thoughts on Web Video </a></li>
<li><a href="/2010/02/26/html5-video-support-detecting-playing-and-progressive-enhancement/" rel="bookmark" title="HTML5 video support. Detecting, playing and progressive enhancement!">HTML5 video support. Detecting, playing and progressive enhancement! </a></li>
<li><a href="/2010/10/26/ffmpeg-libx264-and-presets/" rel="bookmark" title="ffmpeg, libx264 and presets">ffmpeg, libx264 and presets </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies</title>
		<link>/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/</link>
		<comments>/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/#comments</comments>
		<pubDate>Wed, 03 Nov 2010 14:19:25 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Apache Corporation]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[Computer memory]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[CPU cache]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[database server]]></category>
		<category><![CDATA[Google Inc.]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTTP cookie]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[MySQL Americas Inc.]]></category>
		<category><![CDATA[Page cache]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[script interpreter]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web app]]></category>
		<category><![CDATA[web application caching]]></category>
		<category><![CDATA[Web application frameworks]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[Zend Technologies]]></category>

		<guid isPermaLink="false">/?p=2024</guid>
		<description><![CDATA[Zend_Cache_Frontend_Page First of all there are several things to know about Zend Framework and caching. Whenever you work on a big web application caching is one of the mostly used mechanisms of speeding up the app and improve user performance. In general the task and the solution are pretty simple and natural. As the application &#8230; <a href="/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/" class="more-link">Continue reading <span class="screen-reader-text">How to Overcome Zend_Cache_Frontend_Page&#8217;s Problem with Cookies</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/01/17/a-memcached-zend_cache/" rel="bookmark" title="A Memcached Zend_Cache">A Memcached Zend_Cache </a></li>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/07/19/zend-framework-cache-database-table-schemes/" rel="bookmark" title="Zend Framework: Cache Database Table Schemes">Zend Framework: Cache Database Table Schemes </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Zend_Cache_Frontend_Page</h2>
<p>First of all there are several things to know about Zend Framework and caching. Whenever you work on a big web application caching is one of the mostly used mechanisms of speeding up the app and improve user performance. In general the task and the solution are pretty simple and natural.</p>
<p>As the application grows up the visitors become more and more impatient about what they receive. A single page is becoming slower and slower and the result is painful. First of all every time a user hits a page the application server uses the web server, a script interpreter, a database server and potentially the file system. But that&#8217;s not all. After all this output is generated on the server, as HTML in the most cases, it is sent to the client where again CSS and JavaScript engines parse and execute them.</p>
<p>In this scenario it&#8217;s easy to imagine how many time is spent. While there are several techniques to optimize the client side by optimizing JavaScript, CSS and the static images used for the design of the site, here I&#8217;m going to talk more about the backend.</p>
<h2>Beside the Optimization</h2>
<p>Let&#8217;s assume we&#8217;ve one of the very used combination between Apache (as a webserver), PHP (as server scripting language) and MySQL (as database server). Here you can choose to optimize all three of them. However beside the optimization of them one of the most simple steps you can do is to cache the output generated by these three branches of your web app.</p>
<h2>Caching the Content</h2>
<p>In fact you can cache only single parts of the whole process. For instance you can cache only the result returned by some slow database query. Let&#8217;s imagine a query takes about 2 seconds to execute. Now you can cache the result into a file and during the cache is active, i.e. it has not expired, the application takes it from a file stored somewhere in the file system.</p>
<p>In a typical Zend Framework scenario you can first setup the frontend and backend options of the cache.</p>
<pre lang="php">
$frontendOptions = array(
	'lifetime'                => 600, // in seconds - this is 10 seconds
	'automatic_serialization' => true,
);
$backendOptions = array('cache_dir' => 'cache/');
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
		
$cacheKey = md5('mykey');

if (!$cache->load($cacheKey)) {
	$slowQueryResult = $article->fetchAll();
	$cache->save($slowQueryResult, $cacheKey);
} else {
	$slowQueryResult = $cache->load($cacheKey);
}
</pre>
<p>You can setup different options here by setting up the cache directory, lifetime, etc.</p>
<p><em>Note that the cache directory must exists and with write permissions and Zend Framework doesn&#8217;t create it for you and will throw error.</em></p>
<p>The problem here is that now you cache only part of the generated content and in many cases this is still too slow for most of the users. However all the work (in most of the cases) of the web server, the script interpreter and the database server result in a simple HTML output. What if you have this output generated or cached for you and when the user hit the page the server will return this pre-generated code?</p>
<p>This is indeed very fast, because it&#8217;s similar to return a text file, as the HTML is simply formatted text.</p>
<h2>Caching the Entire Page</h2>
<p>Before I proceed, I&#8217;d like to say that I work with Zend Framework 1.9.x. Now in the latest versions of ZF there are new mechanisms of caching the output even Zend_Cache_Frontend_Page works fine on them.</p>
<p>You can simply setup the page cache within few simple lines of code:</p>
<pre lang="php">
$fo = array(
    'lifetime' => 600,
    'regexps' => array(
        '^/' => array(
	'cache' => true,
         'cache_with_cookie_variables' => true,
        ),
    )
);

$bo = array(
    'cache_dir' => 'cache/'
);

$cache = Zend_Cache::factory('Page', 'File', $fo, $bo);
$cache->start();
</pre>
<p>However my advise is to place this code as high as possible, because this will cache everything generated as output. It&#8217;s a good practice if you place this even in the bootstrap before you make the connection with the database. Actually you don&#8217;t need a database connection when you&#8217;ve to return a simple text(html) file.</p>
<p>This will improve your app&#8217;s performance a lot!</p>
<p>However there are few things to know. When you setup the cache to work even with cookie variables, you can see that hitting the page with different browsers Zend Framework will generated different cache pages. This is quite useless because than you don&#8217;t have any benefit of caching the content.</p>
<p>First of all let me say that THIS IS NOT A BUG! of ZF. Simply the framework will use the cookie variables to generate the cache key. It&#8217;s obvious that different browsers, even more different users, will have different cookie set and the framework will generate different cache keys for them.</p>
<p>Thus you&#8217;ve to change the setting to generate the cache key from cookie variable by explicitly set this option to false:</p>
<pre lang="php">
$fo = array(
    'lifetime' => 600,
    'regexps' => array(
        '^/' => array(
		 'cache' => true,
         'cache_with_cookie_variables' => true,
         'make_id_with_cookie_variables' => false,
        ),
    )
);

$bo = array(
    'cache_dir' => 'cache/'
);

$cache = Zend_Cache::factory('Page', 'File', $fo, $bo);
$cache->start();
</pre>
<p>Note that in this example we cache every single page generated by the framework explained in the regexps. This is not so good especially when the users have the possibility to login and to see customized content for them, so you can be careful what you cache.</p>
<p>A typical problem that this solution solves is when your application uses Google Analytics. As you may know Google Analytics sets up a cookie every time when an user hits the page, so every time the framework will generate a different cache for him and in result he won&#8217;t see any benefit and performance improvement from your site.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/01/17/a-memcached-zend_cache/" rel="bookmark" title="A Memcached Zend_Cache">A Memcached Zend_Cache </a></li>
<li><a href="/2010/01/27/theory-of-caching-zend_cache-zend-optimizer/" rel="bookmark" title="Theory of caching. Zend_Cache &#038; Zend Optimizer.">Theory of caching. Zend_Cache &#038; Zend Optimizer. </a></li>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/07/19/zend-framework-cache-database-table-schemes/" rel="bookmark" title="Zend Framework: Cache Database Table Schemes">Zend Framework: Cache Database Table Schemes </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/11/03/how-to-overcome-zend_cache_frontend_pages-problem-with-cookies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HTTP POST with PHP without cURL</title>
		<link>/2010/09/08/http-post-with-php-without-curl/</link>
		<comments>/2010/09/08/http-post-with-php-without-curl/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 21:47:27 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Truth]]></category>

		<guid isPermaLink="false">/?p=1960</guid>
		<description><![CDATA[Awesome PHP It&#8217;s strange how powerful PHP can be. There&#8217;s a legend that cURL is the only way to perform a HTTP POST with PHP, but that isn&#8217;t the truth. An extremely useful script is by using stream_context_create: $optional_headers = null; $params = array('http' => array( 'method' => 'POST', 'content' => http_build_query(array('name' => 'my-name')))); if &#8230; <a href="/2010/09/08/http-post-with-php-without-curl/" class="more-link">Continue reading <span class="screen-reader-text">HTTP POST with PHP without cURL</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/04/13/post-with-zend_http_client/" rel="bookmark" title="POST with Zend_Http_Client">POST with Zend_Http_Client </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/05/17/php-the-array-element-doesnt-exist-suppress-the-warnings/" rel="bookmark" title="PHP: The Array Element Doesn&#8217;t Exist &#8211; Suppress the Warnings">PHP: The Array Element Doesn&#8217;t Exist &#8211; Suppress the Warnings </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Awesome PHP</h2>
<p><a href="/wp-content/uploads/2010/09/idea.jpeg"><img src="/wp-content/uploads/2010/09/idea.jpeg" alt="a great php idea!" title="idea" width="430" height="286" class="aligncenter size-full wp-image-1975" srcset="/wp-content/uploads/2010/09/idea.jpeg 430w, /wp-content/uploads/2010/09/idea-300x199.jpg 300w" sizes="(max-width: 430px) 100vw, 430px" /></a><br />
It&#8217;s strange how powerful PHP can be. There&#8217;s a legend that cURL is the only way to perform a HTTP POST with PHP, but that isn&#8217;t the truth. An extremely useful script is by using stream_context_create:</p>
<pre lang="php">
$optional_headers = null;
$params = array('http' => array(
                'method' => 'POST',
                'content' => http_build_query(array('name' => 'my-name'))));

if ($optional_headers !== null) {
    $params['http']['header'] = $optional_headers;
}

$ctx = stream_context_create($params);
$fp = @fopen('http://example.com/post.php', 'rb', false, $ctx);
</pre>
<p>Well this is only a snippet. You can change a lot this code and perform any request, but here&#8217;s a small start up. However note that this will do the same as while posting to example.com/post.php via web form!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/04/13/post-with-zend_http_client/" rel="bookmark" title="POST with Zend_Http_Client">POST with Zend_Http_Client </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/05/17/php-the-array-element-doesnt-exist-suppress-the-warnings/" rel="bookmark" title="PHP: The Array Element Doesn&#8217;t Exist &#8211; Suppress the Warnings">PHP: The Array Element Doesn&#8217;t Exist &#8211; Suppress the Warnings </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/09/08/http-post-with-php-without-curl/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Setting Up Zend Framework with Modules</title>
		<link>/2010/08/06/setting-up-zend-framework-with-modules/</link>
		<comments>/2010/08/06/setting-up-zend-framework-with-modules/#respond</comments>
		<pubDate>Fri, 06 Aug 2010 12:59:21 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Front Controller pattern]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[modular zend]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Software architecture]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Software framework]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[zend framework modules]]></category>

		<guid isPermaLink="false">/?p=1826</guid>
		<description><![CDATA[Typical Zend App Typically you&#8217;ve one module in your Zend App &#8211; the default one. In the basic installation of the framework, you put all the controllers, models and views directly in the application folder, as described below. /application - /controllers - /IndexController.php - /models - /MyModel.php - /views - /scripts - /index/index.phtml /library - &#8230; <a href="/2010/08/06/setting-up-zend-framework-with-modules/" class="more-link">Continue reading <span class="screen-reader-text">Setting Up Zend Framework with Modules</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Typical Zend App</h2>
<p>Typically you&#8217;ve one module in your Zend App &#8211; the default one. In the basic installation of the framework, you put all the controllers, models and views directly in the application folder, as described below.</p>
<pre lang="php">
/application
	- /controllers
		- /IndexController.php
	- /models
		- /MyModel.php
	- /views
		- /scripts
			- /index/index.phtml
/library
	- /Zend
/public_html
	- /images
	- /scripts
</pre>
<h2>Bigger Apps &#8211; More Code</h2>
<p>When the application becomes bigger and bigger the controller, models and views/scripts directories contain more and more files. That&#8217;s a bit odd, because it becomes difficult to maintain, and than the modules come in hand.</p>
<h2>Modules in a Zend App</h2>
<p>When it comes to setting up modular Zend App there are tons of articles in the web, but let me show you a simple directory layout and &#8230; sample code that sets up the framework.</p>
<pre lang="php">
/application
	- /modules
		+ /admin
			- /controllers
				- /IndexController.php
			- /views
				- /scripts
					- /index/index.phtml
		+ /default
			- /controllers
				- /IndexController.php
			- /views
				- /scripts
					- /index/index.phtml
	- /models
/library
	- /Zend
/public_html
	- /images
	- /scripts
</pre>
<h2>Source</h2>
<p>Simply add this into the bootstrap:</p>
<pre lang="php">
$frontController->addModuleDirectory(APPLICATION_PATH . '/modules');
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/21/setting-up-global-cache-in-zend-framework/" rel="bookmark" title="Setting Up Global Cache in Zend Framework">Setting Up Global Cache in Zend Framework </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/06/setting-up-zend-framework-with-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend_Mail with GMail</title>
		<link>/2010/07/18/zend_mail-with-gmail/</link>
		<comments>/2010/07/18/zend_mail-with-gmail/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 11:39:20 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computer-mediated communication]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[Gmail]]></category>
		<category><![CDATA[Gmail interface]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[Simple Mail Transfer Protocol]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1817</guid>
		<description><![CDATA[You know how to setup Zend_Mail with SMTP, but you don&#8217;t know how to set it up with GMail! Here&#8217;s how to do it. Just follow the instructions 😉 $mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array( 'auth' => 'login', 'username' => 'xxxxxx@gmail.com', 'password' => 'passxxxxx', 'port' => '587', 'ssl' => 'tls', )); Zend_Mail::setDefaultTransport($mailTransport);<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/25/send-mail-with-zend-framework/" rel="bookmark" title="Send Mail with Zend Framework">Send Mail with Zend Framework </a></li>
<li><a href="/2010/07/17/send-html-mails-with-zend_mail/" rel="bookmark" title="Send Html Mails with Zend_Mail">Send Html Mails with Zend_Mail </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/07/20/zend-framework-connect-mysql/" rel="bookmark" title="Zend Framework: Connect MySQL">Zend Framework: Connect MySQL </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2010/07/zend_mail_gmail.jpg"><img src="/wp-content/uploads/2010/07/zend_mail_gmail.jpg" alt="Zend_Mail and GMail" title="zend_mail_gmail" width="250" height="370" class="aligncenter size-full wp-image-1821" srcset="/wp-content/uploads/2010/07/zend_mail_gmail.jpg 250w, /wp-content/uploads/2010/07/zend_mail_gmail-202x300.jpg 202w" sizes="(max-width: 250px) 100vw, 250px" /></a><br />
You know how to setup Zend_Mail with SMTP, but you don&#8217;t know how to set it up with GMail! Here&#8217;s how to do it. Just follow the instructions <img src="https://s.w.org/images/core/emoji/11/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<pre lang="php">
$mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
    'auth'     => 'login',
    'username' => 'xxxxxx@gmail.com',
    'password' => 'passxxxxx',
    'port'     => '587',
    'ssl'      => 'tls',
));
Zend_Mail::setDefaultTransport($mailTransport);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/25/send-mail-with-zend-framework/" rel="bookmark" title="Send Mail with Zend Framework">Send Mail with Zend Framework </a></li>
<li><a href="/2010/07/17/send-html-mails-with-zend_mail/" rel="bookmark" title="Send Html Mails with Zend_Mail">Send Html Mails with Zend_Mail </a></li>
<li><a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" rel="bookmark" title="Send Authenticated POST Request with Zend_Http_Client">Send Authenticated POST Request with Zend_Http_Client </a></li>
<li><a href="/2010/07/20/zend-framework-connect-mysql/" rel="bookmark" title="Zend Framework: Connect MySQL">Zend Framework: Connect MySQL </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/18/zend_mail-with-gmail/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Zend Framework: Inject JavaScript Code in a Action/View</title>
		<link>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/</link>
		<comments>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 14:39:49 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Client-side JavaScript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Printf]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=1666</guid>
		<description><![CDATA[There is a view helper that can inject a head or inline script into your code. Simply by putting some JavaScript code into the view script wont do the job, because the .phtml file is grabbed and parsed by the Zend Framework and thus the code there wont be parsed as JavaScript and it wont &#8230; <a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" class="more-link">Continue reading <span class="screen-reader-text">Zend Framework: Inject JavaScript Code in a Action/View</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>There is a view helper that can inject a head or inline script into your code.</p>
<p>Simply by putting some JavaScript code into the view script wont do the job, because the .phtml file is grabbed and parsed by the Zend Framework and thus the code there wont be parsed as JavaScript and it wont be executed as well by the browser.</p>
<h2>The Most Simple Way &#8230;</h2>
<p>is to put some place holder into the layout .phtml file and than from the controller&#8217;s action you can assign some JS code:</p>
<pre lang="php">
// layout.phtml
<?php
...
echo $this->layout()->scriptTags;
...
</pre>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function indexAction() 
	{
		$this->view->layout()->scriptTags = '<script src="my.js"></script>';	
	}	
}
</pre>
<h2>Solution No. 2</h2>
<p>Although the first solution is correct it&#8217;s not the most clearest way, because you put the JavaScript code into the PHP, and this sooner or later becomes a mess. </p>
<pre lang="php">
<?php

class IndexController extends Zend_Controller_Action
{
	public function indexAction() 
	{
		$this->view->layout()->scriptTags = '<script src="my.js"></script>';
						  . '<script>alert("here\'s my" + "test")</script>';
	}	
}
</pre>
<p>The IDE is not highlighting the code, and you&#8217;ve to deal with too many quotes, which is bad! There is a better solution however &#8211; the inline script:</p>
<pre lang="php">
// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
</pre>
<h2>Simply the Best</h2>
<p>Yeah, the best solution is something even better than the second one. Although the solution I&#8217;ve just mentioned is fine for including JS files, when you&#8217;ve to add some JS code you&#8217;ll have to put it again into the PHP. </p>
<pre lang="php">
$msg = 'some dynamically generated message';

// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
$scripts->appendScript('alert("' . $msg . '")');
</pre>
<p>If there&#8217;s no relation between JavaScript and PHP you can simply put all this code into a separate .js file and load it from there. This is by the way the best solution because the file is cached by the browser, if the cache is enabled. But most of the time you perhaps have to send some variables from PHP to the JavaScript code.</p>
<p>It would be perfect if you had some kind of a variable placeholders &#8211; exactly as you have it in the Zend Framework&#8217;s view scripts!</p>
<h3>Another View</h3>
<p>This is completely possible &#8211; just forget about the default view &#8211; it renders the view script and it&#8217;s bind to the /views/scripts folder. You can make another, completely new, view instead! Here&#8217;s some source:</p>
<pre lang="php">
$view = new Zend_View();
$view->setBasePath('path_to_the_js_folder');

$view->msg = 'Some dynamically generated message';

// script tags
/* @var $scripts Zend_View_Helper_InlineScript */
$scripts = $this->view->inlineScript();
$scripts->appendFile('my.js');
$scripts->appendScript($view->render('inline.js'));
</pre>
<p>Thus now in the JS file you can have some placeholders!</p>
<pre lang="javascript">
// inline.js

// some js code
// ...
alert('<?php echo $this->msg ?>');
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/23/bind-zend-action-with-non-default-view-part-2/" rel="bookmark" title="Bind Zend Action with Non-Default View &#8211; Part 2">Bind Zend Action with Non-Default View &#8211; Part 2 </a></li>
<li><a href="/2010/06/07/bind-zend-action-with-non-default-view/" rel="bookmark" title="Bind Zend Action with Non-Default View">Bind Zend Action with Non-Default View </a></li>
<li><a href="/2010/01/29/escaping-strings-in-a-zend-framework-view-prevent-unclosed-tags/" rel="bookmark" title="Escaping strings in a Zend Framework view. Prevent unclosed tags!">Escaping strings in a Zend Framework view. Prevent unclosed tags! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP Coding Style: Large IF Statements</title>
		<link>/2010/05/25/php-coding-style-large-if-statements/</link>
		<comments>/2010/05/25/php-coding-style-large-if-statements/#comments</comments>
		<pubDate>Tue, 25 May 2010 12:17:26 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Initialisms]]></category>
		<category><![CDATA[Law/Crime]]></category>
		<category><![CDATA[Lincoln cent]]></category>
		<category><![CDATA[Muse Records]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1562</guid>
		<description><![CDATA[Have you ever seen some PHP code like that: if ($condition1 &#038;& $condition2 &#038;& $string1 == $string2 . $string3 &#038;& $string4 != $string5 . $string6) { // write some code here!? } It is ugly, isn&#8217;t it? I&#8217;d prefer to make it clearer! What about that? if ($condition1 &#038;& $condition2 &#038;& $string1 == $string2 . &#8230; <a href="/2010/05/25/php-coding-style-large-if-statements/" class="more-link">Continue reading <span class="screen-reader-text">PHP Coding Style: Large IF Statements</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Have you ever seen some PHP code like that:</p>
<pre lang="php" line="1">
if ($condition1 && $condition2 && $string1 == $string2 . $string3 && $string4 != $string5 . $string6) {
   // write some code here!?
}
</pre>
<p>It is ugly, isn&#8217;t it?</p>
<p>I&#8217;d prefer to make it clearer! What about that?</p>
<pre lang="php" line="1">
if ($condition1 
   && $condition2
   && $string1 == $string2
                . $string3
   && $string4 != $string5
                . $string6
) {
   // write some code here
}
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/03/10/php-if-else-endif-statements/" rel="bookmark" title="PHP if-else-endif Statements">PHP if-else-endif Statements </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/25/php-coding-style-large-if-statements/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
