<?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>unix &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/unix/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>An FFMPEG Question &#8211; Why PHP&#8217;s exec() Doesn&#8217;t Return the Command Output</title>
		<link>/2011/04/12/an-ffmpeg-question-why-phps-exec-doesnt-return-the-command-output/</link>
		<comments>/2011/04/12/an-ffmpeg-question-why-phps-exec-doesnt-return-the-command-output/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 08:19:00 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Application software]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Dc]]></category>
		<category><![CDATA[Exec]]></category>
		<category><![CDATA[FFmpeg]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Standard streams]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">/?p=2293</guid>
		<description><![CDATA[string exec (&#8230;) Here&#8217;s the tricky part. As we know from the exec() man page this function executes the given command. As described there, the exact declaration of this method is: string exec ( string $command [, array &#038;$output [, int &#038;$return_var ]] ) So far so good. Normally exec() will return the output of &#8230; <a href="/2011/04/12/an-ffmpeg-question-why-phps-exec-doesnt-return-the-command-output/" class="more-link">Continue reading <span class="screen-reader-text">An FFMPEG Question &#8211; Why PHP&#8217;s exec() Doesn&#8217;t Return the Command Output</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/10/26/ffmpeg-libx264-and-presets/" rel="bookmark" title="ffmpeg, libx264 and presets">ffmpeg, libx264 and presets </a></li>
<li><a href="/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/" rel="bookmark" title="How to Make MP4 Progressive with qt-faststart">How to Make MP4 Progressive with qt-faststart </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/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>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>string exec (&#8230;)</h2>
<p>Here&#8217;s the tricky part. As we know from the <a title="PHP exec() Function Man Page" href="http://php.net/manual/en/function.exec.php" target="_blank">exec() man page</a> this function <em>executes the given command</em>. As described there, the exact declaration of this method is:</p>
<pre lang="php">
string exec  ( string $command  [, array &$output  [, int &$return_var  ]] )
</pre>
<p>So far so good. Normally exec() will return the output of the command.</p>
<pre lang="bash">
FFmpeg version SVN-r21880, Copyright (c) 2000-2010 Fabrice Bellard, et al.
  built on Feb 18 2010 15:53:28 with gcc 4.3.2
  configuration: --enable-gpl --enable-nonfree --enable-shared --enable-postproc --enable-avfilter --enable-avfilter-lavf --enable-pthreads --enable-x11grab --enable-bzlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-version3 --enable-libdc1394 --enable-libfaac --enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libschroedinger --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-zlib --prefix=/usr/local
  libavutil     50. 9. 0 / 50. 9. 0
  libavcodec    52.54. 0 / 52.54. 0
  libavformat   52.52. 0 / 52.52. 0
  libavdevice   52. 2. 0 / 52. 2. 0
  libavfilter    1.17. 0 /  1.17. 0
  libswscale     0.10. 0 /  0.10. 0
  libpostproc   51. 2. 0 / 51. 2. 0
...
</pre>
<p>However sometimes that is not so true. Let&#8217;s see an example with the popular FFMPEG program. In one hand when you try to start a video converting program with <a href="/category/php/">PHP</a> you can simply call exec with the <a href="/tag/ffmpeg/">FFMPEG</a> command as the first parameter. The output is OK and you can dump it as in the example here.</p>
<pre lang="php">
echo exec('/usr/local/bin/ffmpeg -i input.mp4 -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre normal -threads 0 output.mp4', $output);	
var_dump($output);
</pre>
<p>In some cases you can call <a href="http://www.ffmpeg.org/" target="_blank">FFMPEG</a> only with the -i option to get some info about the input file. Such info can be the size of the image, the bitrate of the source file or the length of the movie. Executing this command:</p>
<pre lang="php">
echo exec('/usr/local/bin/ffmpeg -i input.mp4', $output);	
var_dump($output);
</pre>
<p>in the terminal you&#8217;ll see the output you wish. However if you trying to execute the command via exec() the output remains empty?</p>
<h2>Why the Output Parameter is Empty?</h2>
<p>Looking at the terminal screen you can&#8217;t see the difference, but actually in the second case, when you execute FFMPEG only with the -i option, the output is redirected to the standard error output. That&#8217;s why you can&#8217;t see it in the exec() second parameter. However there is a solution.</p>
<figure id="attachment_2300" style="width: 500px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/04/help.jpg"><img class="size-full wp-image-2300" title="PHP's exec() Doesn't Return The Command Output Always" src="/wp-content/uploads/2011/04/help.jpg" alt="Sometimes PHP's exec() doesn't return the command output. You've to be sure that the command output is not redirected to the standard error stream." width="500" height="375" srcset="/wp-content/uploads/2011/04/help.jpg 500w, /wp-content/uploads/2011/04/help-300x225.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></a><figcaption class="wp-caption-text">Sometimes PHP&#39;s exec() doesn&#39;t return the command output. You&#39;ve to be sure that the command output is not redirected to the standard error stream.</figcaption></figure>
<h2>Solution and Conclusion</h2>
<p>The solution is quite simple. You&#8217;ve to redirect the output of the FFMPEG command to the standard output.</p>
<pre lang="bash">
/usr/local/bin/ffmpeg -i /var/www/android/test.mp4 2>&1
</pre>
<p>Now you can call this line with exec().</p>
<pre lang="php">
echo exec('/usr/local/bin/ffmpeg -i input.mp4 2>&1', $output);	
var_dump($output);
</pre>
<p>This showcase with the FFMPEG is important not only because now you can call FFMPEG&#8217;s command without problems, but because you now know that exec() can&#8217;t read the standard error output. Thus you&#8217;ve to be careful and always redirect to the standard output.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/10/26/ffmpeg-libx264-and-presets/" rel="bookmark" title="ffmpeg, libx264 and presets">ffmpeg, libx264 and presets </a></li>
<li><a href="/2010/11/12/how-to-make-mp4-progressive-with-qt-faststart/" rel="bookmark" title="How to Make MP4 Progressive with qt-faststart">How to Make MP4 Progressive with qt-faststart </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/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>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/04/12/an-ffmpeg-question-why-phps-exec-doesnt-return-the-command-output/feed/</wfw:commentRss>
		<slash:comments>10</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>Connect MySQL from Zend Server CE trough unix socket!</title>
		<link>/2009/12/09/connect-mysql-from-zend-server-ce-trough-unix-socket/</link>
		<comments>/2009/12/09/connect-mysql-from-zend-server-ce-trough-unix-socket/#respond</comments>
		<pubDate>Wed, 09 Dec 2009 19:18:31 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[mysql socket]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[zend server ce]]></category>

		<guid isPermaLink="false">/?p=828</guid>
		<description><![CDATA[First of all, let me introduce you to my case. I&#8217;m working on a Mac with both Xampp and Zend Server CE. Both have separate MySQL servers installed from their default installation on my machine. Both have their separate phpMyAdmins. The one thing I couldn&#8217;t find in the man page of Zend Server CE is &#8230; <a href="/2009/12/09/connect-mysql-from-zend-server-ce-trough-unix-socket/" class="more-link">Continue reading <span class="screen-reader-text">Connect MySQL from Zend Server CE trough unix socket!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/20/zend-framework-connect-mysql/" rel="bookmark" title="Zend Framework: Connect MySQL">Zend Framework: Connect MySQL </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>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2012/06/07/php-and-mysql-natural-sort/" rel="bookmark" title="PHP and MySQL Natural Sort">PHP and MySQL Natural Sort </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>First of all, let me introduce you to my case. I&#8217;m working on a Mac with both Xampp and Zend Server CE. Both have separate MySQL servers installed from their default installation on my machine. Both have their separate phpMyAdmins.</p>
<p>The one thing I couldn&#8217;t find in the man page of Zend Server CE is how to I access this MySQL server installation from my PHP scripts.</p>
<p>The answer is quite simple &#8211; trough UNIX socket. The ZS CE default db socket is:</p>
<blockquote>
<pre>/usr/local/zend/mysql/tmp/mysql.sock</pre>
</blockquote>
<p>and yet again let me say that this is for Mac.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/20/zend-framework-connect-mysql/" rel="bookmark" title="Zend Framework: Connect MySQL">Zend Framework: Connect MySQL </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>
<li><a href="/2010/08/06/setting-up-zend-framework-with-modules/" rel="bookmark" title="Setting Up Zend Framework with Modules">Setting Up Zend Framework with Modules </a></li>
<li><a href="/2012/06/07/php-and-mysql-natural-sort/" rel="bookmark" title="PHP and MySQL Natural Sort">PHP and MySQL Natural Sort </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2009/12/09/connect-mysql-from-zend-server-ce-trough-unix-socket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
