<?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>http &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/http/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>You think you know javascript. Quiz results!</title>
		<link>/2012/03/07/you-think-you-know-javascript-quiz-results/</link>
		<comments>/2012/03/07/you-think-you-know-javascript-quiz-results/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 10:27:37 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[quiz]]></category>
		<category><![CDATA[Client-side JavaScript]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=2854</guid>
		<description><![CDATA[After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on! 1. Which loop is faster in JavaScript? for while correct answer 2. What will be alerted by the code bellow? var str = 'my-'; alert(str.split('-')[1]); Error An empty string correct answer &#8220;-&#8220; &#8220;my&#8221; 3. What is server-side JavaScript? JS scripts &#8230; <a href="/2012/03/07/you-think-you-know-javascript-quiz-results/" class="more-link">Continue reading <span class="screen-reader-text">You think you know javascript. Quiz results!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on!</p>
<p><strong>1. Which loop is faster in JavaScript?</strong></p>
<ul>
<li>for</li>
<li>while <span style="color: #339966;">correct answer</span></li>
</ul>
<p><figure id="attachment_2883" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer1.png"><img src="/wp-content/uploads/2012/03/answer1.png" alt="Answers of the first question chart" title="Answers of the first question chart" width="600" height="371" class="size-full wp-image-2883" srcset="/wp-content/uploads/2012/03/answer1.png 600w, /wp-content/uploads/2012/03/answer1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure><br />
<span id="more-2854"></span><br />
<strong>2. What will be alerted by the code bellow? </strong></p>
<pre lang="javascript">var str = 'my-'; alert(str.split('-')[1]);</pre>
<ul>
<li>Error</li>
<li>An empty string <span style="color: #339966;">correct answer</span></li>
<li>&#8220;-&#8220;</li>
<li>&#8220;my&#8221;</li>
</ul>
<figure id="attachment_2885" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer2.png"><img src="/wp-content/uploads/2012/03/answer2.png" alt="Answers of the second question chart" title="Answers of the second question chart" width="600" height="371" class="size-full wp-image-2885" srcset="/wp-content/uploads/2012/03/answer2.png 600w, /wp-content/uploads/2012/03/answer2-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure>
<p><strong>3. What is server-side JavaScript?</strong></p>
<ul>
<li>JS scripts files placed on the server that can be publicly accessed by the client</li>
<li>JS engine running on the server accessible via http <span style="color: #339966;">correct answer</span></li>
</ul>
<figure id="attachment_2887" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer3.png"><img src="/wp-content/uploads/2012/03/answer3.png" alt="Answers of the third question chart" title="Answers of the third question chart" width="600" height="371" class="size-full wp-image-2887" srcset="/wp-content/uploads/2012/03/answer3.png 600w, /wp-content/uploads/2012/03/answer3-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">90.91% right answers</figcaption></figure>
<p><strong>4. Is it possible to have private and public methods in a JavaScript object</strong></p>
<ul>
<li>Yes <span style="color: #339966;">correct answer</span></li>
<li>No</li>
</ul>
<figure id="attachment_2889" style="width: 540px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer4.png"><img src="/wp-content/uploads/2012/03/answer4.png" alt="Answers of the fourth question chart" title="Answers of the fourth question chart" width="540" height="331" class="size-full wp-image-2889" srcset="/wp-content/uploads/2012/03/answer4.png 540w, /wp-content/uploads/2012/03/answer4-300x183.png 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption class="wp-caption-text">54.55% answered with the right answer!</figcaption></figure>
<p><em>Note that the quiz will remain open, but no results will be published!</em></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/03/07/you-think-you-know-javascript-quiz-results/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP: Fetch $_GET as String with http_build_query()</title>
		<link>/2011/08/17/php-fetch-get-as-string-with-http_build_query/</link>
		<comments>/2011/08/17/php-fetch-get-as-string-with-http_build_query/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 07:42:24 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[elegant solution]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[http_build_query]]></category>
		<category><![CDATA[php reference]]></category>
		<category><![CDATA[Query string]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=2358</guid>
		<description><![CDATA[PHP is really full of functions for everything! Most of the time when you try to do something with strings, there&#8217;s a function that can do it better and faster. The Route from $_GET to String The global arrays in PHP contain request parameters. Either GET or POST. As you know if the page address &#8230; <a href="/2011/08/17/php-fetch-get-as-string-with-http_build_query/" class="more-link">Continue reading <span class="screen-reader-text">PHP: Fetch $_GET as String with http_build_query()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<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/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/09/08/http-post-with-php-without-curl/" rel="bookmark" title="HTTP POST with PHP without cURL">HTTP POST with PHP without cURL </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><strong>PHP</strong> is really full of functions for everything! Most of the time when you try to do something with strings, there&#8217;s a function that can do it better and faster. </p>
<h2>
The Route from $_GET to String<br />
</h2>
<p>The global arrays in PHP contain request parameters. Either <a href="http://php.net/manual/en/reserved.variables.get.php" title="PHP: $_GET - Manual" target="_blank">GET</a> or <a href="http://www.php.net/manual/en/reserved.variables.post.php" title="PHP: $_POST - Manual" target="_blank">POST</a>. As you know if the page address is something like:</p>
<pre lang="PHP">
http://www.example.com/index.php?a=b&key=value
</pre>
<p>This means that you pass to the index.php file two parameters &#8211; &#8220;a&#8221; and &#8220;key&#8221; with their values: &#8220;b&#8221; and &#8220;value&#8221;. Now in this case you can dump the $_GET <strong>global array</strong> somewhere in index.php and you&#8217;ll receive something like this.</p>
<pre lang="PHP">
array(
	"a"   => "b",
	"key" => "value",
);
</pre>
<p>This is however pseudocode, but in fact $_GET will be very similar to this sample array. <span id="more-2358"></span></p>
<h2>
$_GET to String<br />
</h2>
<p>Very often when a developer need to process the $_GET array to a string, which means generating again the query string from $_GET, he often comes to some operation like this one.</p>
<pre lang="PHP">
$queryString = '';
foreach ($_GET as $key => $value) {
	$queryString .= $key . '=' . $value . '&';
}
</pre>
<p>However this will result in something quite ugly like <b>a=b&#038;key=value&#038;</b> which comes with a trailing &#038; at the end of the string.</p>
<p>There is however another approach &#8211; using an array.</p>
<pre lang="PHP">
$queryString = array();
foreach ($_GET as $key => $value) {
	$queryString[] = $key . '=' . $value;
}
$queryString = implode('&', $queryString);
</pre>
<p>But that invokes one function more and this is still not the most elegant solution. As I said at the beginning PHP is full of useful functions and here comes the <a href="http://php.net/manual/en/function.http-build-query.php" title="PHP: http_build_query - Manual" target="_blank">http_build_query</a>.</p>
<h2>
http_build_query<br />
</h2>
<p>This is exactly what you need. As it name describe you can build the query string even by using a different from &#038; separator.</p>
<pre lang="PHP">
$queryString = http_build_query($_GET, '', '|');
</pre>
<p>Thus $queryString will contain <strong>a=b|key=value</strong> and at least the code will look pritier.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<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/16/zend-examples-get-parameters-default-value/" rel="bookmark" title="Zend Examples: GET Parameters Default Value">Zend Examples: GET Parameters Default Value </a></li>
<li><a href="/2010/09/17/5-php-string-functions-you-need-to-know/" rel="bookmark" title="5 PHP String Functions You Need to Know">5 PHP String Functions You Need to Know </a></li>
<li><a href="/2010/09/08/http-post-with-php-without-curl/" rel="bookmark" title="HTTP POST with PHP without cURL">HTTP POST with PHP without cURL </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/08/17/php-fetch-get-as-string-with-http_build_query/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>POST with Zend_Http_Client</title>
		<link>/2011/04/13/post-with-zend_http_client/</link>
		<comments>/2011/04/13/post-with-zend_http_client/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 13:26:47 +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 networking]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[CURL]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[Internet protocols]]></category>
		<category><![CDATA[Network protocols]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[World Wide Web]]></category>
		<category><![CDATA[Zend Technologies]]></category>

		<guid isPermaLink="false">/?p=2299</guid>
		<description><![CDATA[CURL and Zend_Http It&#8217;s a well know fact that you can preform HTTP requests with CURL. Zend Framework does the same job with Zend_Http. Especially Zend_Http_Client can be used to &#8220;replace&#8221; the usual client &#8211; the browser, and to perform some basic requests. I&#8217;ve seen mostly GET requests, although Zend_Http_Client can perform various requests such &#8230; <a href="/2011/04/13/post-with-zend_http_client/" class="more-link">Continue reading <span class="screen-reader-text">POST with Zend_Http_Client</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<li><a href="/2011/04/07/use-fopen-to-check-file-availability/" rel="bookmark" title="Use fopen() to Check File Availability?">Use fopen() to Check File Availability? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>CURL and Zend_Http</h2>
<p>It&#8217;s a well know fact that you can preform <a title="Http Requests - the Hypertext Transfer Protocol" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" target="_blank">HTTP requests</a> with <a href="http://en.wikipedia.org/wiki/CURL" title="CURL" target="_blank">CURL</a>. <a title="Zend Framework" href="http://framework.zend.com/" target="_blank">Zend Framework</a> does the same job with <a title="Zend_Http" href="http://framework.zend.com/manual/en/zend.http.html" target="_blank">Zend_Http</a>. Especially <a title="Http on Stoimen.com" href="/tag/http/">Zend_Http_Client</a> can be used to &#8220;replace&#8221; the usual client &#8211; the browser, and to perform some basic requests.</p>
<figure id="attachment_2308" style="width: 450px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/http.jpg"><img class="size-full wp-image-2308" title="HTTP requests can be performed with Zend_Http_Client" src="/wp-content/uploads/2011/04/http.jpg" alt="HTTP requests can be performed with Zend_Http_Client" width="450" height="337" srcset="/wp-content/uploads/2011/04/http.jpg 450w, /wp-content/uploads/2011/04/http-300x224.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /></a><figcaption class="wp-caption-text">Zend_Http_Client is mostly used to perform GET requests, but it can be also very helpful for POST HTTP requests.</figcaption></figure>
<p>I&#8217;ve seen mostly GET requests, although Zend_Http_Client can perform various requests such as <a title="POST Requests on Stoimen.com" href="/tag/post/">POST</a> as well.</p>
<pre lang="php">
// new HTTP request to some HTTP address
$httpClient = new Zend_Http_Client('http://www.example.com/');
// GET the response
$response = $httpClient->request(Zend_Http_Client::GET);
</pre>
<p>Here&#8217;s a little snippet showing how to POST some data to a server.</p>
<pre lang="php">
// new HTTP request to some HTTP address
$client = new Zend_Http_Client('http://www.example.com/');
// set some parameters
$client->setParameterPost('name', 'value');
// POST request
$response = $client->request(Zend_Http_Client::POST);
</pre>
<p>Note that the request method returns a response. Thus if you are simulating a form submit action you can &#8220;redirect&#8221; to the desired page just like the form.</p>
<pre lang="php">
// new HTTP request to some HTTP address
$client = new Zend_Http_Client('http://www.example.com/');
// set some parameters
$client->setParameterPost('name', 'value');
// POST request
$response = $client->request(Zend_Http_Client::POST);
echo $response->location;
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<li><a href="/2011/04/07/use-fopen-to-check-file-availability/" rel="bookmark" title="Use fopen() to Check File Availability?">Use fopen() to Check File Availability? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/04/13/post-with-zend_http_client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Use fopen() to Check File Availability?</title>
		<link>/2011/04/07/use-fopen-to-check-file-availability/</link>
		<comments>/2011/04/07/use-fopen-to-check-file-availability/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 12:46:33 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[C file input/output]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[HEAD]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=2268</guid>
		<description><![CDATA[Zend Framework and Zend_Http_Client I&#8217;ve posted about Zend_Http_Client. Simply there you can &#8216;make&#8217; your own http client and you can request a remote file. Just to check what&#8217;s going on with this file. // new HTTP request to a file $httpClient = new Zend_Http_Client('http://www.example.com/myfile.mp4'); // get the HEAD of the response and match agains the &#8230; <a href="/2011/04/07/use-fopen-to-check-file-availability/" class="more-link">Continue reading <span class="screen-reader-text">Use fopen() to Check File Availability?</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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/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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Zend Framework and Zend_Http_Client</h2>
<figure id="attachment_2287" style="width: 450px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/file.jpg"><img class="size-full wp-image-2287" title="PHP's fopen() can be used to check remote file existence" src="/wp-content/uploads/2011/04/file.jpg" alt="PHP's fopen() can be used to check remote file existence" width="450" height="415" srcset="/wp-content/uploads/2011/04/file.jpg 450w, /wp-content/uploads/2011/04/file-300x276.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /></a><figcaption class="wp-caption-text">PHP&#39;s fopen() can be used to check remote file existence</figcaption></figure>
<p>I&#8217;ve posted about <a title="Zend Http Client Class Docs" href="http://framework.zend.com/manual/en/zend.http.client.advanced.html" target="_blank">Zend_Http_Client</a>. Simply there you can &#8216;make&#8217; your own http client and you can request a remote file. Just to check what&#8217;s going on with this file.</p>
<pre lang="php" escaped="true">// new HTTP request to a file
$httpClient = new Zend_Http_Client('http://www.example.com/myfile.mp4');

// get the HEAD of the response and match agains the
// Content-Length. That's because using the Content-Type is slower
$response = $httpClient-&gt;request(Zend_Http_Client::HEAD);

// if the Content-Length is 0 the file doesn't exists
if (0 === (int)$response-&gt;getHeader('Content-Length')) {
	echo 'the file doesn\'t exits';
}
</pre>
<p>However is there any other way to answer the same question?</p>
<h2>fopen()</h2>
<p>Yes and no? Perhaps yes, but you should be careful. I&#8217;m still not sure it can be used in any case. However here&#8217;s the snippet.</p>
<pre lang="php" escaped="true">if (FALSE === @fopen('http://www.example.com/myfile.mp4', 'r')) {
	echo 'the file doesn\'t exists';
}
</pre>
<p><a title="fopen() PHP Manpage" href="http://php.net/manual/en/function.fopen.php" target="_blank">fopen()</a> will return FALSE whenever the file doesn&#8217;t exists.</p>
<p>In both cases I request a remote file &#8211; an MPEG-4 file. Note that fopen()&#8217;s first parameter can be a HTTP resource.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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/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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/04/07/use-fopen-to-check-file-availability/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://www.example.com/myfile.mp4" length="0" type="video/mp4" />
		</item>
		<item>
		<title>Diving into Node.js &#8211; A Long Polling Example</title>
		<link>/2010/12/02/diving-into-node-js-a-long-polling-example/</link>
		<comments>/2010/12/02/diving-into-node-js-a-long-polling-example/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 09:51:48 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[chat-like applications]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[Internet protocols]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[long polling server]]></category>
		<category><![CDATA[Node]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[real time data]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[typical web server]]></category>
		<category><![CDATA[web developers]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[web servers]]></category>
		<category><![CDATA[World Wide Web]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">/?p=2041</guid>
		<description><![CDATA[Node.js vs. The World What is typical for most of the web servers is that they listen for requests and respond as quickly as possible on every one of them. In fact the speed of the response is one of the main targets of optimization for developers. Fast servers are what everyone needs. From web &#8230; <a href="/2010/12/02/diving-into-node-js-a-long-polling-example/" class="more-link">Continue reading <span class="screen-reader-text">Diving into Node.js &#8211; A Long Polling Example</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/11/19/diving-into-node-js-very-first-app/" rel="bookmark" title="Diving into Node.js &#8211; Very First App">Diving into Node.js &#8211; Very First App </a></li>
<li><a href="/2010/11/16/diving-into-node-js-introduction-and-installation/" rel="bookmark" title="Diving into Node.js &#8211; Introduction &#038; Installation">Diving into Node.js &#8211; Introduction &#038; Installation </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Node.js vs. The World</h2>
<p><a href="/wp-content/uploads/2010/11/node-js.jpg"><img class="aligncenter size-full wp-image-2088" title="node js" src="/wp-content/uploads/2010/11/node-js.jpg" alt="" width="445" height="193" srcset="/wp-content/uploads/2010/11/node-js.jpg 445w, /wp-content/uploads/2010/11/node-js-300x130.jpg 300w" sizes="(max-width: 445px) 100vw, 445px" /></a></p>
<p>What is typical for most of the web servers is that they listen for requests and respond as quickly as possible on every one of them. In fact the speed of the response is one of the main targets of optimization for developers. Fast servers are what everyone needs. From web developers to website visitors!</p>
<p>In the field of the that battle different web servers have different &#8220;weapons&#8221; to gain time. While this is useful in most of the cases, when it comes to a chat-like applications and <a title="Node.js" href="http://nodejs.org/" target="_blank">Node.js</a> approaches, the response is not always immediately returned. As I described in my <a title="Diving into Node.js – Very First App" href="/2010/11/19/diving-into-node-js-very-first-app/" target="_self">posts</a> until now about Node.js, a simple web server may wait for an event to be emitted, and than return the response.<span id="more-2041"></span></p>
<p>I wrote about <a title="Diving into Node.js – Very First App" href="/2010/11/19/diving-into-node-js-very-first-app/" target="_self">how to write the very first server</a>, but than I didn&#8217;t described how to make a &#8220;non-responding&#8221; server. By the term &#8220;non-responding&#8221; I mean a server that responds not immediately after it has received and parsed/executed the request.</p>
<p>A typical web server, responding immediately on every request, written with Node, this may look like so:</p>
<pre lang="javascript">var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
</pre>
<p>The code that shows us that the request is executed and responds in these lines:</p>
<pre lang="javascript">  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
</pre>
<p>Actually by commenting/removing those lines you&#8217;ll get a server that simply doesn&#8217;t respond &#8211; ever! This of course is not the main goal, but you can start from somewhere.</p>
<pre lang="javascript">var http = require('http');
http.createServer(function (req, res) {
  // res.writeHead(200, {'Content-Type': 'text/plain'});
  // res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
</pre>
<p>This is how you can hold for a while. Perhaps putting these lines in a conditional statement and periodically checking for some event to occur will do the job.</p>
<pre lang="javascript">var http = require('http');
http.createServer(function (req, res) {
  if (something) {
     res.writeHead(200, {'Content-Type': 'text/plain'});
     res.end('Hello World\n');
  }
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');
</pre>
<h2>Looping Server</h2>
<p>As described in the code above if you put the respond into a conditional you can possibly return the response after some event has fired. The only thing is to periodically loop and check for this condition to be true. Assuming your server&#8217;s code is in server.js, started with the &#8220;node server.js&#8221; command, you&#8217;ve to put this code into it:</p>
<pre lang="javascript" escaped="true">var http = require("http"),
    fs	 = require("fs");  

// we create a server with automatically binding
// to a server request listener
http.createServer(function(request, response) {
	checkFile(request, response);
}).listen(8124);

function checkFile(request, response)
{
	var date = new Date();
	if (date-request.socket._idleStart.getTime() &gt; 59999) {
		response.writeHead(200, {
			'Content-Type'   : 'text/plain',
			'Access-Control-Allow-Origin' : '*'
		});

		// return response
		response.write('OK', 'utf8');
		response.end();
	}

	// we check the information from the file, especially
	// to know when it was changed for the last time
	fs.stat('filepath', function(err, stats) {
		// if the file is changed
		if (stats.mtime.getTime() &gt; request.socket._idleStart.getTime()) {
			// read it
			fs.readFile('filepath', 'utf8', function(err, data) {
				// return the contents
				response.writeHead(200, {
					'Content-Type'   : 'text/plain',
					'Access-Control-Allow-Origin' : '*'
				});

				// return response
				response.write(data, 'utf8');
				response.end();

				// return
				return false;
			});
		}
	});	

	setTimeout(function() { checkFile(request, response) }, 10000);
};
</pre>
<p>Note: you must change &#8220;filepath&#8221; with an existing file path in your system.</p>
<p>Here we can read periodically the file&#8217;s mtime, which is the modify time. Thus whenever the file is changed the server will return the response. It&#8217;s interesting to note that if no change occurs within the timeout period you&#8217;ve to return some status message as we did in those lines:</p>
<pre lang="javascript" escaped="true">        
var date = new Date();
if (date-request.socket._idleStart.getTime() > 59999) {
	response.writeHead(200, {
		'Content-Type'   : 'text/plain',
		'Access-Control-Allow-Origin' : '*'
	});
	
	// return response
	response.write('OK', 'utf8');
	response.end();
}
</pre>
<p>The client side should long poll this server. The example bellow is written in jQuery. The only &#8220;special&#8221; thing is that after receiving the response, you must call the server again.</p>
<h3>The Client</h3>
<p>The client is nothing new to the jQuery/JavaScript community except you must call again the server when the response is returned:</p>
<pre lang="javascript">function callNode() {
    $.ajax({
        cache : false,
		// setup the server address
        url : 'http://www.example.com:8124/',
        data : {},
        success : function(response, code, xhr) {

            if ('OK' == response) {
            	callNode();
                return false;
            }

            // do whatever you want with the response
            ...

            // make new call
            callNode();
        }
    });
};
callNode();
</pre>
<h2>Summary</h2>
<p>As Node can hold the response, the only thing you should do is to check periodically for something as in this example this was a file change. Than it&#8217;s important to change the client so it can call the server after the response from it is received.</p>
<p>Typically Node can be used for chat-like applications or whatever apps that must deliver real time data, but for sure it is really great software.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/11/19/diving-into-node-js-very-first-app/" rel="bookmark" title="Diving into Node.js &#8211; Very First App">Diving into Node.js &#8211; Very First App </a></li>
<li><a href="/2010/11/16/diving-into-node-js-introduction-and-installation/" rel="bookmark" title="Diving into Node.js &#8211; Introduction &#038; Installation">Diving into Node.js &#8211; Introduction &#038; Installation </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/12/02/diving-into-node-js-a-long-polling-example/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Diving into Node.js &#8211; Very First App</title>
		<link>/2010/11/19/diving-into-node-js-very-first-app/</link>
		<comments>/2010/11/19/diving-into-node-js-very-first-app/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 09:55:36 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Computer networking]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[Internet protocols]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Localhost]]></category>
		<category><![CDATA[Network architecture]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[port While]]></category>
		<category><![CDATA[server on nodejs]]></category>
		<category><![CDATA[Server-side JavaScript]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">/?p=2066</guid>
		<description><![CDATA[What do I have till now? After Node.js is istalled, described in my previous post, I can simply run this command: stoimenpopov:~# node server.js and this will start the server with the code within server.js. But what&#8217;s the code of server.js? Following the instructions of Node&#8217;s homepage and most of the tutorials I&#8217;ve found, I &#8230; <a href="/2010/11/19/diving-into-node-js-very-first-app/" class="more-link">Continue reading <span class="screen-reader-text">Diving into Node.js &#8211; Very First App</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/12/02/diving-into-node-js-a-long-polling-example/" rel="bookmark" title="Diving into Node.js &#8211; A Long Polling Example">Diving into Node.js &#8211; A Long Polling Example </a></li>
<li><a href="/2010/11/16/diving-into-node-js-introduction-and-installation/" rel="bookmark" title="Diving into Node.js &#8211; Introduction &#038; Installation">Diving into Node.js &#8211; Introduction &#038; Installation </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>What do I have till now?</h2>
<p>After Node.js is istalled, described in <a href="/2010/11/16/diving-into-node-js-introduction-and-installation/" target="_self">my previous post</a>, I can simply run this command:</p>
<blockquote><p>stoimenpopov:~# node server.js</p></blockquote>
<p>and this will start the server with the code within server.js. But what&#8217;s the code of server.js?</p>
<p>Following the instructions of <a title="Nodejs" href="http://nodejs.org/" target="_blank">Node&#8217;s homepage</a> and most of the tutorials I&#8217;ve found, I can simply copy/paste the code from the first lines of Node&#8217;s page:</p>
<pre lang="javascript">var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');</pre>
<p>There are several things I find interesting in this code, making it different from JavaScript as we know it. First of all what is</p>
<blockquote><p>var http = require(&#8216;http&#8217;)</p></blockquote>
<p>and why I need it? What is the purpouse of 8124 and 127.0.0.1?</p>
<p>Node is built in modules and to use one of them you must first include it with <strong>require</strong>. Just like the example above with require(&#8216;http&#8217;). In the same manner you can include every module of Node.</p>
<p>What are the Node&#8217;s modules are pretty well described in <a title="Node.js API" href="http://nodejs.org/docs/v0.2.5/api.html" target="_blank">the API page</a>. Well I&#8217;d like to say that the API page is quite insufficient. That is very bad, cause most of the code you&#8217;ll need developing a node.js applicatoin isn&#8217;t described/explained there.<span id="more-2066"></span></p>
<p>However is more than obvious that 8124 is the port, while 127.0.0.1 is the IP address of the server, which in this case is the localhost. Thus after running the server and typing http://127.0.0.1:8124/ into your browser you&#8217;ll get &#8220;Hello World&#8221;. This is not enough when the server is running on a remote machine, while you&#8217;ve to access it from your local computer.</p>
<h2>The first server</h2>
<p>As I described the code above shows you an example server. In fact the API page shows a slightly different code:</p>
<pre lang="javascript">var http = require('http');

http.createServer(function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello World\n');
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');</pre>
<p>Here the line:</p>
<pre lang="javascript">}).listen(8124);</pre>
<p>omits the address of the server. It appears to be non-required and the server is supposed to listen on this machine on the given port. To be honest I&#8217;m not sure why you&#8217;ve to write the server address, except for limit the possible address to this one. However in my case the server was installed on a remote machine indeed, while I was trying to access it from my local machine. So here are some base steps to do before accomplishing this.</p>
<h3>1. Changing the IP address</h3>
<p>First of all you can omit the IP address. This can help you move the code from one server to another without changing the code.</p>
<pre lang="javascript">}).listen(8124, ip_address);</pre>
<p>possibly a better solution is:</p>
<pre lang="javascript">}).listen(8124);</pre>
<p>Node can listen on whatever port you say so this is up to you to decide which port should be opened.</p>
<h3>2. Opening the port</h3>
<p>While everything&#8217;s on the localhost you wont have problems with port opening. If you&#8217;d like to access it remotely however, you&#8217;ve to open the port. In other words http://127.0.0.1:8124/ is OK without port opening, but http://example.com:8124/ &#8211; is not!</p>
<p>To open a port in UNIX/Linux you&#8217;ve to type this command in the terminal:</p>
<pre lang="bash">iptables -A INPUT -p tcp --dport 8124 -j ACCEPT</pre>
<p>don&#8217;t forget to change the port number from 8124 to whatever port number you&#8217;re using.</p>
<h3>3. The first AJAX call</h3>
<p>We still cannot make the first AJAX call to the Node server. Here I&#8217;m using <a title="jQuery" href="http://jquery.com/" target="_blank">jQuery</a> because of the easy AJAX interface.</p>
<pre lang="javascript">$(document).ready(function() {
	$.ajax({
    	// setup the server address
        url : 'http://example:8124/',
        success : function(response) {
        	// on success
        	alert(response);
		},
        error : function() {
        	// on error
        }
    });
});</pre>
<p>After executing this code in a browser there wont be a response. That is because of the remote AJAX calls restriction. To overcome this you&#8217;ve to change the returned header from the Node&#8217;s server, by adding this:</p>
<pre lang="javascript">'Access-Control-Allow-Origin' : '*'</pre>
<p>Now server.js will look like this:</p>
<pre lang="javascript">var http = require('http');

http.createServer(function (request, response) {
	response.writeHead(200, {
		'Content-Type': 'text/plain',
		'Access-Control-Allow-Origin' : '*'
	});
	response.end('Hello World\n');
}).listen(8124);</pre>
<p>you can now either load http://example.com:8124/ into your browser or to make the AJAX call. In both cases the answer will be &#8220;Hello World&#8221;</p>
<h2>Summary</h2>
<p>Now you have a very simple Node.js server. Well it is nothing special as it responses with &#8220;Hello World&#8221; on every request, but it works remotely.</p>
<p>Soon I&#8217;ll describe how to change the server so it can waits to respond until some event is emitted &#8211; which is the real power of Node.js.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/12/02/diving-into-node-js-a-long-polling-example/" rel="bookmark" title="Diving into Node.js &#8211; A Long Polling Example">Diving into Node.js &#8211; A Long Polling Example </a></li>
<li><a href="/2010/11/16/diving-into-node-js-introduction-and-installation/" rel="bookmark" title="Diving into Node.js &#8211; Introduction &#038; Installation">Diving into Node.js &#8211; Introduction &#038; Installation </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/11/19/diving-into-node-js-very-first-app/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Replace the Broken Images with a Default Image with JavaScript</title>
		<link>/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/</link>
		<comments>/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 12:35:33 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1738</guid>
		<description><![CDATA[There is cool JavaScript trick that helps you catch broken images. You know that when the image doesn&#8217;t exist, the http path to the image returns 404 or the path is wrong, the browser doesn&#8217;t display nothing in the most cases. As MSIE is always different it displays an ugly icon saying that there is &#8230; <a href="/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/" class="more-link">Continue reading <span class="screen-reader-text">Replace the Broken Images with a Default Image with JavaScript</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2009/08/05/jquery-check-whether-image-is-loaded/" rel="bookmark" title="jQuery: check whether image is loaded">jQuery: check whether image is loaded </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>There is cool JavaScript trick that helps you catch broken images. You know that when the image doesn&#8217;t exist, the http path to the image returns 404 or the path is wrong, the browser doesn&#8217;t display nothing in the most cases. As MSIE is always different it displays an ugly icon saying that there is not an image to load</p>
<p><a href="/wp-content/uploads/2010/07/msie-broken-image.png"><img src="/wp-content/uploads/2010/07/msie-broken-image.png" alt="MSIE broken image icon" title="msie-broken-image" width="148" height="224" class="aligncenter size-full wp-image-1747" /></a></p>
<p>and that is really bad!</p>
<h2>There&#8217;s a Quick Fix &#8230;</h2>
<p>Simply add an onerror handler on the IMG tag</p>
<pre lang="html4strict">
<img src="http://..../broken_url.jpg" onerror="this.src='path_to_default_image'" />
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
<li><a href="/2009/08/05/jquery-check-whether-image-is-loaded/" rel="bookmark" title="jQuery: check whether image is loaded">jQuery: check whether image is loaded </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Send Authenticated POST Request with Zend_Http_Client</title>
		<link>/2010/06/28/send-authenticated-post-request-with-zend_http_client/</link>
		<comments>/2010/06/28/send-authenticated-post-request-with-zend_http_client/#respond</comments>
		<pubDate>Mon, 28 Jun 2010 19:01:44 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[Computer networking]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-site request forgery]]></category>
		<category><![CDATA[Form]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[Network protocols]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[Representational State Transfer]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=1697</guid>
		<description><![CDATA[There is an easy way to send requests with Zend_Http_Client either in GET and POST. Actually you can request not only with GET and POST methods, but with any other http request method. $httpClient = new Zend_Http_Client('http://..../'); // request via post $response = $httpClient->request(Zend_Http_Client::POST); // or get $response = $httpClient->request(Zend_Http_Client::GET); However the interesting and useful &#8230; <a href="/2010/06/28/send-authenticated-post-request-with-zend_http_client/" class="more-link">Continue reading <span class="screen-reader-text">Send Authenticated POST Request with Zend_Http_Client</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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a href="/wp-content/uploads/2010/06/authentication.jpg"><img src="/wp-content/uploads/2010/06/authentication.jpg" alt="" title="authentication" width="300" height="230" class="aligncenter size-full wp-image-1716" /></a><br />
There is an easy way to send requests with <a title="Zend_Http_Client" href="http://framework.zend.com/manual/en/zend.http.client.html" target="_blank">Zend_Http_Client</a> either in GET and POST. Actually you can request not only with GET and POST methods, but with any other http request method.</p>
<pre lang="php">
$httpClient = new Zend_Http_Client('http://..../');
// request via post
$response = $httpClient->request(Zend_Http_Client::POST);
// or get
$response = $httpClient->request(Zend_Http_Client::GET);
</pre>
<p>However the interesting and useful thing is that you can perform authenticated requests:</p>
<pre lang="php">
$httpClient = new Zend_Http_Client('http://username:password@example.com/');
// or define it later
$httpClient = new Zend_Http_Client('http://example.com/');
$httpClient->setAuth('username', 'password');
</pre>
<p>That&#8217;s an opportunity to send/receive authenticated POST requests.</p>
<pre lang="php">
$httpClient = new Zend_Http_Client('http://username:password@example.com/');
// now post
$httpClient->request(Zend_Http_Client::POST);
</pre>
<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/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/03/23/read-remote-file-content-type-with-zend_http_client/" rel="bookmark" title="Read Remote File Content-Type with Zend_Http_Client">Read Remote File Content-Type with Zend_Http_Client </a></li>
<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>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/28/send-authenticated-post-request-with-zend_http_client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check YouTube Video Existence with Zend_Gdata_YouTube</title>
		<link>/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/</link>
		<comments>/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/#respond</comments>
		<pubDate>Fri, 21 May 2010 07:43:57 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[e->]]></category>
		<category><![CDATA[Entertainment/Culture]]></category>
		<category><![CDATA[GData]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Hypertext Transfer Protocol]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web application frameworks]]></category>
		<category><![CDATA[World Wide Web]]></category>
		<category><![CDATA[YouTube]]></category>
		<category><![CDATA[YouTube Inc]]></category>

		<guid isPermaLink="false">/?p=1531</guid>
		<description><![CDATA[The Video Has Been Removed?! Have you ever seen the famous message on YouTube: &#8220;This video has been removed by the user.&#8221;, but what if you&#8217;re trying to grab that video via the Zend_Gdata_YouTube? That can happen when you&#8217;re reading the feed for a channel or a user&#8217;s list of videos. In the feed everything&#8217;s &#8230; <a href="/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/" class="more-link">Continue reading <span class="screen-reader-text">Check YouTube Video Existence with Zend_Gdata_YouTube</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/16/retrieving-youtube-channels-videos-with-zend_gdata_youtube/" rel="bookmark" title="Retrieving YouTube Channel&#8217;s Videos with Zend_Gdata_YouTube">Retrieving YouTube Channel&#8217;s Videos with Zend_Gdata_YouTube </a></li>
<li><a href="/2010/04/22/iterate-over-youtube-channel-with-zend_gdata_youtube/" rel="bookmark" title="Iterate over YouTube Channel with Zend_Gdata_YouTube">Iterate over YouTube Channel with Zend_Gdata_YouTube </a></li>
<li><a href="/2010/01/23/youtube-and-vimeo-goes-html5-with-video-tag-usage-catch-them-up/" rel="bookmark" title="YouTube and Vimeo goes HTML5 with video tag usage! Catch them up!">YouTube and Vimeo goes HTML5 with video tag usage! Catch them up! </a></li>
<li><a href="/2011/04/07/use-fopen-to-check-file-availability/" rel="bookmark" title="Use fopen() to Check File Availability?">Use fopen() to Check File Availability? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>The Video Has Been Removed?!</h2>
<p>Have you ever seen the famous message on <a href="http://youtube.com/">YouTube</a>: &#8220;This video has been removed by the user.&#8221;, but what if you&#8217;re trying to grab that video via the <a href="http://framework.zend.com/manual/en/zend.gdata.youtube.html" target="_blank">Zend_Gdata_YouTube</a>?</p>
<p>That can happen when you&#8217;re reading the feed for a channel or a user&#8217;s list of videos. In the feed everything&#8217;s OK &#8211; once the video is uploaded it appears into the feed. After that the user removes the video and visiting the link from the feed you&#8217;ll get the message above.</p>
<p>Actually what happens when you try to read this &#8220;video entry&#8221; within a Zend Framework&#8217;s application. There must be some way to catch this message?</p>
<h2>Trying to Catch</h2>
<p>The answer is pretty simple! Zend_Gdata_YouTube&#8217;s throwing an exception and it can be easily cached. Here&#8217;s some source code:</p>
<pre lang="php">
$apiKey = 'your_api_key';
$client = new Zend_Http_Client();
$gdata = new Zend_Gdata_YouTube($client, 'my-app', null, $apiKey);
try {
       $gdata->getVideoEntry($video_id);
} catch(Zend_Gdata_App_Exception $e) {
       echo $e->getMessage();
}
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/16/retrieving-youtube-channels-videos-with-zend_gdata_youtube/" rel="bookmark" title="Retrieving YouTube Channel&#8217;s Videos with Zend_Gdata_YouTube">Retrieving YouTube Channel&#8217;s Videos with Zend_Gdata_YouTube </a></li>
<li><a href="/2010/04/22/iterate-over-youtube-channel-with-zend_gdata_youtube/" rel="bookmark" title="Iterate over YouTube Channel with Zend_Gdata_YouTube">Iterate over YouTube Channel with Zend_Gdata_YouTube </a></li>
<li><a href="/2010/01/23/youtube-and-vimeo-goes-html5-with-video-tag-usage-catch-them-up/" rel="bookmark" title="YouTube and Vimeo goes HTML5 with video tag usage! Catch them up!">YouTube and Vimeo goes HTML5 with video tag usage! Catch them up! </a></li>
<li><a href="/2011/04/07/use-fopen-to-check-file-availability/" rel="bookmark" title="Use fopen() to Check File Availability?">Use fopen() to Check File Availability? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All the Site in &#8230; One Request</title>
		<link>/2010/04/24/all-the-site-in-one-request/</link>
		<comments>/2010/04/24/all-the-site-in-one-request/#respond</comments>
		<pubDate>Sat, 24 Apr 2010 12:58:28 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Delimiter]]></category>
		<category><![CDATA[E-mail]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[MIME]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Usenet]]></category>

		<guid isPermaLink="false">/?p=1479</guid>
		<description><![CDATA[Is it possible? Yes it is! Actually I stumbled these days on a video where one of the guys talked about a quite interesting technique, that all the site was sent in one response from the server. But how is it possible? Actually everything is collected on the server side, i.e. with PHP which groups &#8230; <a href="/2010/04/24/all-the-site-in-one-request/" class="more-link">Continue reading <span class="screen-reader-text">All the Site in &#8230; One Request</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<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/02/05/css-sprites-go-beyond-the-limits-with-base64/" rel="bookmark" title="CSS sprites. Go beyond the limits with base64!">CSS sprites. Go beyond the limits with base64! </a></li>
<li><a href="/2010/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/01/13/optimizing-the-web-start-with-the-images/" rel="bookmark" title="Optimizing the web. Start with the images!">Optimizing the web. Start with the images! </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Is it possible?</h2>
<p>Yes it is! Actually I stumbled these days on a <a href="http://www.yuiblog.com/blog/2010/04/21/video-hpjs/" target="_blank">video</a> where one of the guys talked about a quite interesting technique, that all the site was sent in one response from the server. But how is it possible? Actually everything is collected on the server side, i.e. with PHP which groups everything within a string. Obviously the images are base64ed. Than everything is send to the client with appropriate delimiters and mime types, and the client separates the string and build ups the page.</p>
<h2>Problems</h2>
<p>Of course there are some problems. First of all, as you may guess, MSIE doesn&#8217;t support base64. Another bad thing is that this isn&#8217;t cacheable.</p>
<h2>One Good Use</h2>
<p>There is however a good place to use this technique. In mobile versions. There is no much need of caches and most of all MSIE is not there!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<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/02/05/css-sprites-go-beyond-the-limits-with-base64/" rel="bookmark" title="CSS sprites. Go beyond the limits with base64!">CSS sprites. Go beyond the limits with base64! </a></li>
<li><a href="/2010/04/14/zend_http_client-and-case-sensitivity/" rel="bookmark" title="Zend_Http_Client and Case Sensitivity">Zend_Http_Client and Case Sensitivity </a></li>
<li><a href="/2010/01/13/optimizing-the-web-start-with-the-images/" rel="bookmark" title="Optimizing the web. Start with the images!">Optimizing the web. Start with the images! </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/04/24/all-the-site-in-one-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
