<?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>setcooki</title>
	<atom:link href="http://set.cooki.me/feed" rel="self" type="application/rss+xml" />
	<link>http://set.cooki.me</link>
	<description>allround developer blog</description>
	<lastBuildDate>Fri, 20 Jan 2012 17:30:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>WordPress + Facebook + DISQUS Mashup Deluxe</title>
		<link>http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe</link>
		<comments>http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe#comments</comments>
		<pubDate>Fri, 13 Jan 2012 12:27:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[bridge]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[disqus]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[widget]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=286</guid>
		<description><![CDATA[Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some new players appeared on the block. So which comment system to pick? It largely depends on the application you build, but if you are looking for a solution with many [...]]]></description>
			<content:encoded><![CDATA[<p>Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some new players appeared on the block. So which comment system to pick? It largely depends on the application you build, but if you are looking for a solution with many social media features -DISQUS may be the one you should be looking at. What if you would like to make a service only based on a commenting system as in saying all content of my website will be user generated! DISQUS is the one to go for &#8230; here is why:</p>
<p><span id="more-286"></span>Introducing <a href="http://roadjunkyguides.com">http://roadjunkyguides.com</a> - a project i developed with friends.</p>
<p>The website is based on WordPress as a CMS and a 100% custom made frontend. The website does not use the official DISQUS WP Plugin since it does not have the features we were looking for and also has some poor implementation for the wp plugin. The commenting syncing is not very convincing. it features a two way sync which i dont see necessary at all. Either you sync from a -&gt; b or b -&gt; a but not a &lt;-&gt; b. There seem to be a lot of people complaining about lost comments and so on. Here as some negative points:</p>
<ul class="inline_list">
<li>two way sync produces more errors and not really needed</li>
<li>it does not update comment details when edited in dsq client or wp backend</li>
<li>poor error handling</li>
<li>no error/event/sync logging</li>
</ul>
<p>In our case we needed a fast and realiable mirroring of all the comments from DISQUS an WP serving as a slave only. Also we needed a true reflection on every change on a comment/thread/profile or whatever (even when an author updates his profile url). So in the end we developed our own implementation of a dsq wp plugin based on a PHP5 class structure for bridging and syncing the comments.</p>
<p>With the comments in sync we have a server side representation of all comments for search, editors picks, and SEO harvest. The service but has more to it. We played around with the DISQUS Client and added some cool features:</p>
<ul class="inline_list">
<li>Identify admins/moderators based on the DSQ request/response object and event handlers + storing profile properties server side in PHP session</li>
<li>Enabling the DISQUS highlight feature as a way to flag and harvest valuable comments</li>
<li>Trigger DISQUS sync on new post event</li>
<li>Bridge highlighted post to twitter account on highlight event in client</li>
<li>Facebook compatible DISQUS Widget for canvas apps</li>
<li>unhighlight comments from wp</li>
<li>and many more features &#8230;</li>
</ul>
<p>Some of the features exploited were probably not intended to be used like this by the DISQUS developers but a mashup is a mashup &#8211; no rules apply. The best thing is that the DISQUS Client and/or the widget wrapping it can be hooked into any other website to harvest comments = content. It works flawless in facebook also replacing the facebook wall as a canvas app &#8211; HA!!! Im so excited to see if it works the way it is intended to &#8230; it has been just released BETA yesterday.</p>
<p>If the service runs stable im thinking of rolling out the DISQUS comment sync as a wp plugin for all those who do not like the official plugin and hardcode the client into their posts, pages or implemented them in their templates. lets see &#8230;</p>
<div id="seo_alrp_related"><h2>Posts Related to WordPress + Facebook + DISQUS Mashup Deluxe</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/325/roadjunkyguides-travel-guide" rel="bookmark">Roadjunkyguides &#8211; Travel guide</a></h3><p>Roadjunkyguides - Travel guide Type: Travel guide Founded: 2012 Website: http://roadjunkyguides.com About: Roadjunkyguides is a true love job - based on the idea that only real travelers ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/318/mysala-social-club" rel="bookmark">Mysala &#8211; social club</a></h3><p>MYSALA Social Club Type: Social/Event Club Founded: 2011 Location: Granada, Spain Website: http://mysala.es About: Since long time it has been a dream to find a place to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/131/gvidget-gis-enabled-video-player" rel="bookmark">Gvidget &#8211; GIS enabled video player</a></h3><p>Video playback with GPS coordinates/track synchronized still remains future? Not quite: The prototype is already 2 years old i think by now. it all started ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roadjunkyguides &#8211; Travel guide</title>
		<link>http://set.cooki.me/archives/325/roadjunkyguides-travel-guide</link>
		<comments>http://set.cooki.me/archives/325/roadjunkyguides-travel-guide#comments</comments>
		<pubDate>Fri, 06 Jan 2012 17:04:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[disqus]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=325</guid>
		<description><![CDATA[Roadjunkyguides is a true love job - based on the idea that only real travelers can provide content for a off-the-beaten-track guide. The usual online and print guides are based on the knowledge of a few or only see a certain side of a country/place for example. Many printed guides are also outdated in the moment they are released since the small but valuable tips/tricks may not be valid anymore. As seen in the Lonely Planet scandal you can not even trust editors since many of them will write on the basis of hearsay and third party information.]]></description>
			<content:encoded><![CDATA[<p><strong>Roadjunkyguides &#8211; Travel guide</strong></p>
<p><strong>Type:</strong> Travel guide<br />
<strong>Founded:</strong> 2012<strong><br />
</strong><strong>Website: </strong><a href="http://roadjunkyguides.com">http://roadjunkyguides.com</a></p>
<p><strong>About:<br />
</strong>Roadjunkyguides is a true love job &#8211; based on the idea that only real travelers can provide content for a off-the-beaten-track guide. The usual online and print guides are based on the knowledge of a few or only see a certain side of a country/place for example. Many printed guides are also outdated in the moment they are released since the small but valuable tips/tricks may not be valid anymore. As seen in the Lonely Planet scandal you can not even trust editors since many of them will write on the basis of hearsay and third party information.</p>
<p>The idea behind Roadjunkyguides is simple as is: let the travelers write their own guidebook. To seed quality content moderators will pick valuable posts for the editors pick section so the quality content can be aggregated to a downloadable guide later on. The Roadjunky network has been around for years and has a large group of followers. With Roadjunkguides we hope to bridge the gap between informational travel websites and user generated travel content.</p>
<p><strong>Website:</strong><br />
The webpage has been set up in WP. The template used is 100% custom made as the many function/plugins used. The heart of the website is the DISQUS commenting system which does not work as a usual blog comment system, but as the actual post/content. The website makes heavy use of the DISQUS API and a custom written wp/dsq plugin takes care of the syncing between the two. A DISQUS widget has been created to be computable as a facebook canvas app so a comment/content thread can be used inside facebook to harvest content. In due time the plan is to roll out distributable widgets, so users can plug a widget into their website to show latest entries and even post directly from there. Coding the website and DISQUS functionality has been real fun. See more about the technology used here: <a title="WordPress + Facebook + DISQUS Mashup Deluxe" href="http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe">WordPress + Facebook + DISQUS mashup deluxe</a></p>
<div id="seo_alrp_related"><h2>Posts Related to Roadjunkyguides - Travel guide</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe" rel="bookmark">WordPress + Facebook + DISQUS Mashup Deluxe</a></h3><p>Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/95/its-done-i-am-online" rel="bookmark">Its done &#8211; i am online</a></h3><p>So this is it - finally i found the time after all these years to set up a blog and combine it with my portfolio ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/318/mysala-social-club" rel="bookmark">Mysala &#8211; social club</a></h3><p>MYSALA Social Club Type: Social/Event Club Founded: 2011 Location: Granada, Spain Website: http://mysala.es About: Since long time it has been a dream to find a place to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/131/gvidget-gis-enabled-video-player" rel="bookmark">Gvidget &#8211; GIS enabled video player</a></h3><p>Video playback with GPS coordinates/track synchronized still remains future? Not quite: The prototype is already 2 years old i think by now. it all started ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/325/roadjunkyguides-travel-guide/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Mysala &#8211; social club</title>
		<link>http://set.cooki.me/archives/318/mysala-social-club</link>
		<comments>http://set.cooki.me/archives/318/mysala-social-club#comments</comments>
		<pubDate>Mon, 19 Dec 2011 14:45:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Projects]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=318</guid>
		<description><![CDATA[Since long time it has been a dream to find a place to a) work and b) occasionally host and do events of various types. In its form it could be called a project place or creative hub because in daytime freelancers of different disciplines work side by side - after work the place changes into a creative space where a lot of different events are hosted. The place has about 120 sqm and has two rooms of 60 and 40 sqm. All the furniture is compact and movable in order to rapidly change according to the need the rooms have to provide. Since its opening in October 2011, we hosted over 15 different events already.]]></description>
			<content:encoded><![CDATA[<p><strong>MYSALA Social Club</strong></p>
<p><strong>Type:</strong> Social/Event Club<br />
<strong>Founded:</strong> 2011<br />
<strong>Location:</strong> Granada, Spain<br />
<strong>Website:</strong> <a href="http://mysala.es">http://mysala.es</a></p>
<p><strong>About:<br />
</strong>Since long time it has been a dream to find a place to a) work and b) occasionally host and do events of various types. In its form it could be called a project place or creative hub because in daytime freelancers of different disciplines work side by side &#8211; after work the place changes into a creative space where a lot of different events are hosted. The place has about 120 sqm and has two rooms of 60 and 40 sqm. All the furniture is compact and movable in order to rapidly change according to the need the rooms have to provide. Since its opening in October 2011, we hosted over 15 different events already.</p>
<p><strong>Website:</strong><br />
The webpage has been done in WordPress and the wonderful organic structure themes from: <a href="http://www.organicthemes.com/themes/structure-theme/">http://www.organicthemes.com/themes/structure-theme/</a>. It has been customized and optimized to suit our needs. We also use the Tribulant newsletter plugin for communication which is probably the only one for wordpress that really works.</p>
<div id="seo_alrp_related"><h2>Posts Related to Mysala - social club</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/325/roadjunkyguides-travel-guide" rel="bookmark">Roadjunkyguides &#8211; Travel guide</a></h3><p>Roadjunkyguides - Travel guide Type: Travel guide Founded: 2012 Website: http://roadjunkyguides.com About: Roadjunkyguides is a true love job - based on the idea that only real travelers ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe" rel="bookmark">WordPress + Facebook + DISQUS Mashup Deluxe</a></h3><p>Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/95/its-done-i-am-online" rel="bookmark">Its done &#8211; i am online</a></h3><p>So this is it - finally i found the time after all these years to set up a blog and combine it with my portfolio ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/318/mysala-social-club/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP/XML based staging script</title>
		<link>http://set.cooki.me/archives/281/phpxml-based-staging-script</link>
		<comments>http://set.cooki.me/archives/281/phpxml-based-staging-script#comments</comments>
		<pubDate>Tue, 06 Dec 2011 15:43:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[staging]]></category>
		<category><![CDATA[sync]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=281</guid>
		<description><![CDATA[There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if you have a multiple remote environments/server in form of a test/staging server in and live productive server. In this case you could of course upload your changes first to the [...]]]></description>
			<content:encoded><![CDATA[<p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if you have a multiple remote environments/server in form of a test/staging server in and live productive server. In this case you could of course upload your changes first to the test server and then do the same to the productive server. That of course has a major disadvantage since you may have made local changes which are not reflected/tested before syncing the two. Suppose you have others testing the application on the test server you are bound to not change anything while in test modus. So if you dont use any sort of cvs/svn system the only reliable way must be to sync the approved changes from the test server to the productive server while you can still locally develop further.</p>
<p><span id="more-281"></span></p>
<p>If you want to keep control of the sync up to the last bit then i am at least not aware of any linux library the gives you full control over the process, logging, test running and so on. Since in one of my projects we needed to find a way to sync multiple servers via a XML configuration file which is created via an admin panel. Since PHP already includes everything needed for a syncing content i set up a sync script which will copy content from one server to another by using PHPs built in sftp functions. Both servers run SSH with passwords so it was rather easy to sync the two. A ssh connections based on keys is also possible but in this case we didnt bother in the first version of the script. When using PHP as a basis for such a script you will not miss anything that a local client like Transmit or FileZilla would also do. The features in the current built:</p>
<ul class="inline_list">
<li>compare by date or file size</li>
<li>skip files by extension, name or folder</li>
<li>exclude folders and subfolders</li>
<li>sync only files since modified date</li>
<li>set global chmod value for all files</li>
<li>resync by looking for abandond files</li>
<li>define multiple sync jobs in on .xml configuration file</li>
<li>run in test modus to output/logfile sync logs before running live</li>
</ul>
<p>The script will only run on PHP &gt; 5.3 and cli command line on Linux and needs SSH2 installed. Its is known that PHPs SSH2 lib is not running stable under each environment. I can not say if its true but the difficulties that came up where in connection with the most crucial part of the script &#8211; copying the files and setting the permission. In the end none but the &#8220;<a href="http://www.php.net/manual/en/function.ssh2-scp-send.php">ssh2_scp_send</a>&#8221; function really worked. All other wrapper methods did not work in the sense that you can not copy a file and change its permission in one shot since the copy action is a asynchronous event and will not report back once copied. The only function that does so is &#8220;<a href="http://www.php.net/manual/en/function.ssh2-scp-send.php">ssh2_scp_send</a>&#8220;.</p>
<p>There are many things that can be of course optimized like: auth with ssh keys, plain ftp support, .. but for a first launch it works as expected. You can find the script here: <a href="https://github.com/setcooki/syncd">https://github.com/setcooki/syncd</a></p>
<div id="seo_alrp_related"><h2>Posts Related to PHP/XML based staging script</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe" rel="bookmark">WordPress + Facebook + DISQUS Mashup Deluxe</a></h3><p>Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe" rel="bookmark">MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</a></h3><p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf" rel="bookmark">PHP &#038; Ghostscript &#8211; Count pages of PDF</a></h3><p>Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/281/phpxml-based-staging-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</title>
		<link>http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe</link>
		<comments>http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe#comments</comments>
		<pubDate>Mon, 24 Oct 2011 20:28:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[256 bit]]></category>
		<category><![CDATA[7-zip]]></category>
		<category><![CDATA[aes]]></category>
		<category><![CDATA[aespipe]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[encrypted]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tar]]></category>
		<category><![CDATA[zip]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=268</guid>
		<description><![CDATA[Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup is one thing &#8211; securing it is another. Here is a way to dump a database and zip it password protected with 7-zip (http://www.7-zip.org) You need to install 7-zip first [...]]]></description>
			<content:encoded><![CDATA[<p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup is one thing &#8211; securing it is another. Here is a way to dump a database and zip it password protected with 7-zip (<a href="http://www.7-zip.org/">http://www.7-zip.org</a>)</p>
<p><span id="more-268"></span></p>
<p>You need to install 7-zip first &#8211; see docs for more. once installed you should read the command line documentation since there are some important flags you should understand. The following script makes a mysql dump with optional conditions, stores the dump first in a .sql dump file, zips the file 7-zip pass protected, removes the original temporary .sql dump file and writes out/err stream to dump log file.</p>
<pre class="brush: php; gutter: true; first-line: 1">

<?php

//do backup
$cmd = null;
$where = "";

$cmd[] = 'mysqldump'
$cmd[] = '--opt';
$cmd[] = '--add-drop-table=true';
$cmd[] = '--create-options=true';
$cmd[] = '--single-transaction=true';
$cmd[] = '--no-autocommit=true';
$cmd[] = '--extended-insert=false';
$cmd[] = '--complete-insert=false';
$cmd[] = '--net_buffer_length=5000';
if(!empty($where))
{
	$cmd[] = '--where="'.$where.'"';
}
$cmd[] = '-h '.$your_db_host;
$cmd[] = '-u '.$your_db_user;
$cmd[] = '\'-p'.$your_db_pass.'\'';
$cmd[] = $your_db_name;
$cmd[] = '> '.$your_path_to_sql_dump.'.sql';
$cmd[] = '&#038;&#038; 7za a -t7z -mx9 -p'.$your_7zip_pass.' '.$your_path_to_7z_file.'.7z '.$your_path_to_sql_dump.'.sql';
$cmd[] = '&#038;&#038; rm '.$your_path_to_sql_dump.'.sql';
$cmd[] = '>> '.$your_path_to_log_file.'-dump.log 2>&#038;1';

if(($proc = proc_open(trim(implode(" ", $cmd)), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes)) !== false)
{
	if(($stdout = stream_get_contents($pipes[1])) === false)
	{
		die("unable open stdout stream");
	}
	if(($stderr = stream_get_contents($pipes[2])) === false)
	{
		die("unable open stderr stream");
	}
	if(!@fclose($pipes[1]))
	{
		die("unable to close stdout stream");
	}
	if(!@fclose($pipes[2]))
	{
		die("unable to close stderr stream");
	}
	if(($res = (int)proc_close($proc)) === -1)
	{
		die("unable to close process");
	}
	if(!empty($stderr))
	{
		die("unable to dump backup, code: $res, error: $stderr");
	}
    echo $stdout;
}else{
	die("unable to execute command");
}

?>
</pre>
<p>In detail: the line: </p>
<p>&#8220;7za a -t7z -mx9 -p&#8217;.$your_7zip_pass.&#8217; &#8216;.$your_path_to_7z_file.&#8217;.7z &#8216;.$your_path_to_sql_dump.&#8217;.sql&#8217;&#8221;</p>
<p>tells 7-zip to make an archive using the standard 7z format and the highest compression ratio. The password is set with the -p switch. The -p with no value will prompt your for an password if called from the shell btw. You can tweak around to see what suits you the best. I had problems with the .tgzip format throwing errors on my server. The 7z format seems to be stable.</p>
<p>7-zip is not the only alternative! You can also use TAR and: http://loop-aes.sourceforge.net/aespipe/ to make an archive and pipe the stream directly into aespipe to encrypt the dump AES 256 Bit. Change the line for 7-zip into: </p>
<p>&#8220;&#038;&#038; tar -cvf &#8216;.$your_path_to_tar_file. &#8216;.tar.aes -C &#8216;.$path.&#8217; &#8211;use-compress-program=/usr/local/bin/bz2aespipe &#8216;.$file.&#8217;.sql&#8221;</p>
<p>The -C switch changes directory to the path where the .sql dump file and the tar is located. the &#8220;&#8211;use-compress-programm&#8221; flag will pipe the tar stream into a wrapper for aespipe which i found somethere (look for bz2aespipe). its content is defined as:</p>
<pre class="brush: php; gutter: true; first-line: 1">
#! /bin/sh

# FILE FORMAT
# 10 bytes: constant string 'bz2aespipe'
# 10 bytes: itercountk digits
# 1 byte: '0' = AES128, '1' = AES192, '2' = AES256
# 1 byte: '0' = SHA256, '1' = SHA384, '2' = SHA512, '3' = RMD160
# 24 bytes: random seed string
# remaining bytes are bzip2 compressed and aespipe encrypted

# These definitions are only used when encrypting.
# Decryption will autodetect these definitions from archive.
ENCRYPTION=AES256
HASHFUNC=SHA256
ITERCOUNTK=100
WAITSECONDS=10
PWDFILE=/usr/local/bin/aespipe.pwd

if test x$1 = x-d ; then
    # decrypt
    n=`head -c 10 - | tr -d -c 0-9a-zA-Z`
    if test x${n} != xbz2aespipe ; then
        echo "bz2aespipe: wrong magic - aborted" >/dev/tty
        exit 1
    fi
    itercountk=`head -c 10 - | tr -d -c 0-9`
    if test x${itercountk} = x ; then itercountk=0; fi
    n=`head -c 1 - | tr -d -c 0-9`
    encryption=AES128
    if test x${n} = x1 ; then encryption=AES192; fi
    if test x${n} = x2 ; then encryption=AES256; fi
    n=`head -c 1 - | tr -d -c 0-9`
    hashfunc=SHA256
    if test x${n} = x1 ; then hashfunc=SHA384; fi
    if test x${n} = x2 ; then hashfunc=SHA512; fi
    if test x${n} = x3 ; then hashfunc=RMD160; fi
    seedstr=`head -c 24 - | tr -d -c 0-9a-zA-Z+/`
    aespipe -e ${encryption} -H ${hashfunc} -S "${seedstr}" -C ${itercountk} -d | bzip2 -d -q
else
    # encrypt
    echo -n bz2aespipe
    echo ${ITERCOUNTK} | awk '{printf "%10u", $1;}'
    n=`echo ${ENCRYPTION} | tr -d -c 0-9`
    aesstr=0
    if test x${n} = x192 ; then aesstr=1; fi
    if test x${n} = x256 ; then aesstr=2; fi
    n=`echo ${HASHFUNC} | tr -d -c 0-9`
    hashstr=0
    if test x${n} = x384 ; then hashstr=1; fi
    if test x${n} = x512 ; then hashstr=2; fi
    if test x${n} = x160 ; then hashstr=3; fi
    seedstr=`head -c 18 /dev/urandom | uuencode -m - | head -n 2 | tail -n 1`
    echo -n ${aesstr}${hashstr}${seedstr}
    bzip2 | aespipe -e ${ENCRYPTION} -H ${HASHFUNC} -S ${seedstr} -P ${PWDFILE} -C ${ITERCOUNTK} -T -w ${WAITSECONDS}
fi
exit 0
</pre>
<p>Note the line &#8220;PWDFILE=/usr/local/bin/aespipe.pwd&#8221; here you must store your password so your are not asked for one and the encrypting will run automatically. I tried the encrypting and decrypting and had no problems. I can not really say if aespipe runs stable or not because in the end i preferred 7-zip with backups stored on a different server via ssh2/sftp and a jail rooted user account. </p>
<p>Both are valid options and a consideration when wanting to have at least some sort of security.</p>
<div id="seo_alrp_related"><h2>Posts Related to MySQL Backups - 7-zip protected AES 256 Bit encrypted</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf" rel="bookmark">PHP &#038; Ghostscript &#8211; Count pages of PDF</a></h3><p>Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/248/get-bookmarks-from-pdf-with-php" rel="bookmark">Get bookmarks from PDF with PHP</a></h3><p>Splitting a PDF according to its Table of Content (Bookmarks) with PHP by using the linux lib http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ you can use the following command to write a ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WP SimpleDesign multi instance Amazon S3 Player Tweak</title>
		<link>http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak</link>
		<comments>http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak#comments</comments>
		<pubDate>Sat, 15 Oct 2011 11:47:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[dewplayer]]></category>
		<category><![CDATA[player]]></category>
		<category><![CDATA[playlist]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[s3]]></category>
		<category><![CDATA[tweak]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=256</guid>
		<description><![CDATA[The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. All you need to do is enter your credentials in the plugin properties in the backend and you are good to go &#8230; But! For some the player simply wont [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer</strong>. See (<a href="http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/">http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/</a>) for more. All you need to do is enter your credentials in the plugin properties in the backend and you are good to go &#8230; But!</p>
<p><span id="more-256"></span></p>
<p>For some the player simply wont do nothing since the credentials (S3 Access Keys) are not valid once passed via GET to PHP file responsible for outputting the .xml string for the Dewplayer. See comments at the developer website for more (<a href="http://www.isimpledesign.co.uk/blog/amazon-s3-music-player-mp3-player-audio-player">http://www.isimpledesign.co.uk/blog/amazon-s3-music-player-mp3-player-audio-player</a>). Also, and this i find a major drawback, it only lets you put one instance of the player across your whole blog. So if you want have multiple instances &#8211; here is what you have to do and tweak:</p>
<ol>
<li>Install the PHP Exec plugin (<a href="http://wordpress.org/extend/plugins/exec-php/">http://wordpress.org/extend/plugins/exec-php/</a>) so you can put php code directly into your post or page</li>
<li>Install the iSimpleDesign plugin and enter your credentials in the backend (leave folder blank!)</li>
<li>Open the file &#8220;amazon-s3-player.php&#8221; in the &#8220;isimpledesign-amazon-s3-music-player-plugin&#8221; plugin folder and change the following code:
<pre class="brush: php; gutter: true; first-line: 1">// Base function
function isd_s3player($_folder = null) {

// Plugin Url
$s3url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));

$amazon_key	= get_option("isd-amazon_key");
$amazon_secret_key	= get_option("isd-amazon_secret_key");
$bucket	= get_option("isd-bucket");
if($_folder !== null)
{
    $folder	= $_folder;
}else{
    $folder	= get_option("isd-folder");
}

$test = $amazon_key."-".$amazon_secret_key."-".$bucket."-".$folder;

....</pre>
<p>this lets you pass a folder name to the php function responsible for generating the playlist .xml list.</li>
<li>then open the file &#8220;playlist.php&#8221; and exchange the following code in the top of the file:
<pre class="brush: php; gutter: true; first-line: 1">$bucket	= $_GET["name"];
$store = explode("-", $bucket);
if(!empty($store[3]))
{
    $store[3] = rtrim($store[3], "/") . "/";
}...</pre>
<p>this is to make sure that we always have a backslash at the end of the folder name. we can now pass the folder name to the player and use multiple instances in the same post or blog.</li>
<li>finally you can use the php function isd_s3player() in your post or page to use multiple instances accross your blog or even post by simple pasting the function with php code directly into the wysiwyg editor like:
<pre class="brush: php; gutter: true; first-line: 1"><?php isd_s3player('myfolder'); ?></pre>
<p> All you need to do is pass the folder name as first parameter of the function et voila.</li>
</ol>
<p>So you could say that only a small backslash did the trick &#8230; Further tweaks could be including a ID3 Parser and extending the configuration so Dewplayer properties can also be controlled from backend.</p>
<p>Hope it helps somebody</p>
<div id="seo_alrp_related"><h2>Posts Related to WP SimpleDesign multi instance Amazon S3 Player Tweak</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/286/wordpress-facebookdisqus-mashup-deluxe" rel="bookmark">WordPress + Facebook + DISQUS Mashup Deluxe</a></h3><p>Comment Systems play a more and more vital part in social media experience. Since google announced to also index the most common commenting systems some ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/325/roadjunkyguides-travel-guide" rel="bookmark">Roadjunkyguides &#8211; Travel guide</a></h3><p>Roadjunkyguides - Travel guide Type: Travel guide Founded: 2012 Website: http://roadjunkyguides.com About: Roadjunkyguides is a true love job - based on the idea that only real travelers ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/95/its-done-i-am-online" rel="bookmark">Its done &#8211; i am online</a></h3><p>So this is it - finally i found the time after all these years to set up a blog and combine it with my portfolio ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Get bookmarks from PDF with PHP</title>
		<link>http://set.cooki.me/archives/248/get-bookmarks-from-pdf-with-php</link>
		<comments>http://set.cooki.me/archives/248/get-bookmarks-from-pdf-with-php#comments</comments>
		<pubDate>Tue, 11 Oct 2011 19:53:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[bookmarks]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[pdftk]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[swf]]></category>
		<category><![CDATA[swttools]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=248</guid>
		<description><![CDATA[Splitting a PDF according to its Table of Content (Bookmarks) with PHP by using the linux lib http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ you can use the following command to write a bookmark structure from a PDF to a .txt file pdftk /tmp/bookmark.pdf dump_data output /tmp/report.txt Use the known PHP exec(), system() commands to execute the command. The result looks like: InfoKey: [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Splitting a PDF according to its Table of Content (Bookmarks) with PHP</strong></p>
<p>by using the linux lib <a href="http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/">http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/</a> you can use the following command to write a bookmark structure from a PDF to a .txt file</p>
<p><span id="more-248"></span></p>
<pre class="brush: php; gutter: true; first-line: 1">pdftk /tmp/bookmark.pdf dump_data output /tmp/report.txt</pre>
<p>Use the known PHP exec(), system() commands to execute the command. The result looks like:</p>
<pre class="brush: php; gutter: true; first-line: 1"> InfoKey: Creator
InfoValue: Writer
InfoKey: Producer
InfoValue: OpenOffice.org 3.3
InfoKey: Author
InfoValue: setcookie
InfoKey: CreationDate
InfoValue: D:20110527153051+02'00'
PdfID0: 51d2362ea610d06bd86af64d44b4f
PdfID1: 51d2362ea610d06bd86af64d44b4f
NumberOfPages: 66
BookmarkTitle: 1 Vorwort
BookmarkLevel: 1
BookmarkPageNumber: 4
BookmarkTitle: 2 Versionen / Historie
BookmarkLevel: 1
BookmarkPageNumber: 4
BookmarkTitle: 3 Allgemein
BookmarkLevel: 1
BookmarkPageNumber: 5
BookmarkTitle: 4 Gateway URL
BookmarkLevel: 1
BookmarkPageNumber: 5
BookmarkTitle: 5 Globale Parameter
BookmarkLevel: 1
BookmarkPageNumber: 5
....</pre>
<p>The result can be parsed into a nested array to iterate of the depths of the structure to split the PDF or use the structure for a Bookmark preview in a JS/AS 3 PDF Viewer.<br />
You should be able to redirect the stdout to gain direct access to the output with PHP rather than writing the report file first. In conjunction with SWFTools a whole PDF &gt; Flash converter can be build.<br />
All OpenSource so need to install PDFLib or whatever.</p>
<p>Good luck</p>
<div id="seo_alrp_related"><h2>Posts Related to Get bookmarks from PDF with PHP</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf" rel="bookmark">PHP &#038; Ghostscript &#8211; Count pages of PDF</a></h3><p>Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/225/php-dom-xml-to-array" rel="bookmark">PHP DOM XML to Array</a></h3><p>What is the fastest way to parse a XML string into a equivalent valid Array representation? I have seen quite some efforts on different blogs ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe" rel="bookmark">MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</a></h3><p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/248/get-bookmarks-from-pdf-with-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Process audio with PHP and Sox</title>
		<link>http://set.cooki.me/archives/234/process-audio-with-php-and-sox</link>
		<comments>http://set.cooki.me/archives/234/process-audio-with-php-and-sox#comments</comments>
		<pubDate>Sun, 02 Oct 2011 20:58:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[audio]]></category>
		<category><![CDATA[lame]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[proc]]></category>
		<category><![CDATA[rendering]]></category>
		<category><![CDATA[samples]]></category>
		<category><![CDATA[sox]]></category>
		<category><![CDATA[wav]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=234</guid>
		<description><![CDATA[You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 &#8230; thinks its not possible? Well it is! This will only work on Linux as you need the sOx Soundexchange Library http://sox.sourceforge.net/ and Lame http://lame.sourceforge.net/. Make sure you have the right versions for your environment installed as the wrong setup [...]]]></description>
			<content:encoded><![CDATA[<p><strong>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 &#8230; thinks its not possible? Well it is!</strong></p>
<p>This will only work on Linux as you need the sOx Soundexchange Library http://sox.sourceforge.net/ and Lame http://lame.sourceforge.net/. Make sure you have the right versions for your environment installed as the wrong setup will not be stable. For installation &#8211; see installation guides on the project websites. Once you have everything up and running you should specify your needs and create a runtime routine for rendering audio on-the-fly.<br />
<span id="more-234"></span><br />
If you want to mix/merg single audio snippets into a single exportable .mp3 file you should first consider that every step will a) consume ram/cpu time b) needs validation since a failure will effect the whole rendering process. The only performant way of processing multiple render task is to work with a background daemon as running process to manage the cue of rendering task.</p>
<p>You may want to use the following PEAR class http://kevin.vanzonneveld.net/techblog/article/create_daemons_in_php/ which has turned out to be quite stable handling a constant load in production environment. The following approach worked well on a web application handling thousands of jobs a day.</p>
<ol>
<li>Prepare and organize your source audio files as .wav in 16-bit 44 Khz (Make sure each file is normalized and starts exactly at 0 sample length)</li>
<li>Create a PHP class structure for representation of the audio files, its properties, eventually breaking down songs, into tracks, segments and parts, represented each by a class so a song track contain segments and a segment can contain parts</li>
<li>if you want to mix sound channels you should make that the base class so each channel can be bounced later as well</li>
<li>Create a job class which can recieve the necessary commands for all audio task, which can be serialized and stored in a database for the deamon to pickup a new job once available</li>
<li>Organize all audio task in classes/or plugins that execute the commands</li>
<li>The deamon itsself should trigger the rendering process and execute all commands in a loop until the last step exporting the final audio file to mp3</li>
</ol>
<div>The way sOx works is in always defining an in and out file for each command. Knowing that you must save every outfile in a temporary folder so the next command can take the outfile as infile. The mix of 2 files will only work if the 2 audio files have the exact same sample length! What if you want to mix one audio part of length x with a part that has more samples? You need to know the exact starting point on where to merge the first part to the second. </p>
<p>You can basically calculate the sample length of a wave file by extracting its header (e.g. http://www.phpclasses.org/browse/file/1582.html) or you know the BPM, signature and bars of a audio part (they must be exact). If you want to make a step sequencer with loops you should know these parameters and the can be stored in a database together with file part, name and so on. Calculate the sample length like:</p></div>
<pre class="brush: php; gutter: true; first-line: 1">protected function getSampleLength($bpm = null, $bars = null, $clock = 4, $rate = 44100)
    {
        $timelength = null;
        $samplelength = null;
        if($bpm !== null &amp;&amp; $bars !== null)
        {
            $timelength     = (float)((int)$bars * (60 * (int)$clock)) / (int)$bpm;
            $samplelength   = ceil(($timelength * (int)$rate) / 1);
            return $samplelength;
        }
    }</pre>
<div>Once you have the sample length you can calculate on each bar the sample start point. You can pass these parameters to the sOx command and you are ready to go. The rest is all functional logic to process each step in rendering step by step, bouncing the outfiles and reusing them in the next rendering step and so on. The more generic you design your application &#8211; the more flexible you can handle each audio effect. The best approach is really simple to create a job class which will handle all commands. It could looks something like this:</div>
<pre class="brush: php; gutter: true; first-line: 1">    System_Daemon::start();

    try
    {
        $db = DBFactory::create(DBFactory::DRIVER_MYSQLI, PSOX::credentials());
        $query = QueryFactory::create(QueryFactory::DRIVER_MYSQL, &amp;$db);

        $ok = 0;

        while(true)
        {
            try
            {
                $ok = 0;

                if(!$db-&gt;isConnected())
                {
                    $db-&gt;reconnect();
                }
                if(($res = $query-&gt;getNextJob()) !== 0)
                {
                    $query-&gt;write($res['job_id'], null, PSOX::FLAG_MIXING);
                    $sox = PSOX::deserialize($res['job_data']);
                    PSOX::log(PSOX::LOG_DEBUG, "job is unserialized for mixing");  

                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_INIT))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_INIT) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_MIX))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_MIX) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_MERGE))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_MERGE) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_MP3))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_MP3) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_COPY))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_COPY) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_CLEAR))
                    {
                        if($err = $sox-&gt;runJob(PSOX::JOB_CLEAR) === true) $ok++;
                    }
                    sleep(1);
                    if($sox-&gt;hasJob(PSOX::JOB_MAIL))
                    {
                        if($sox-&gt;runJob(PSOX::JOB_MAIL) === true) $ok++;
                    }
                    if($ok === $sox-&gt;countJobs())
                    {
                        $query-&gt;write($res['job_id'], null, PSOX::FLAG_DONE, null, $sox-&gt;runtime($sox-&gt;getOption(PSOX::OPTION_RUNTIME_START), microtime()));
                        $sox-&gt;publish($res['job_cid']);
                        PSOX::log(PSOX::LOG_DEBUG, "job is done");
                    }else{
                        throw new PSOXException("unable to process job: ".$res['job_id'], PSOX::DAEMON_PROCEED);
                    }
                }
            }
            catch(PSOXException $e)
            {
                if((int)$e-&gt;getCode() === PSOX::DAEMON_ABORT)
                {
                    PSOX::log(PSOX::LOG_ERROR, $e-&gt;getMessage());
                    echo $e-&gt;getMessage();
                    break;
                    System_Daemon::stop();
                }else{
                    $query-&gt;bounceJob($res['job_id']);
                    PSOX::log(PSOX::LOG_ERROR, $e-&gt;getMessage());
                    PSOX::log(PSOX::LOG_DEBUG, "job is bounced");
                }
            }
            sleep(10);
        }
    }
    catch(PSOXException $e)
    {
        PSOX::log(PSOX::LOG_ERROR, $e-&gt;getMessage());
        echo $e-&gt;getMessage();
        System_Daemon::stop();
    }</pre>
<div>How do you communicate with sOx and lame though? A simple PHPs exec(); will not do since error/pipe/output handling is too limited. Here is the method i used to have maximum control using PHPs proc extension:</div>
<pre class="brush: php; gutter: true; first-line: 1">class PROC extends PSOX
{
    /**
    * @desc method that does a proc_open command call with the command set
    * in first parameter $cmd. if the second parameter $output is set to false
    * the command will produce no output thus only returning true if command has
    * terminated
    * @param    string $cmd expects the command to call
    * @param    boolean $output expects whether to look for output
    * @param    array $env optionals env options
    * @param    string $cwd optional working dir
    * @access   public
    * @returns  mixed when $output = true returns string, else either empty string or true
    */
    public static function exec($cmd = null, $output = true, $env = null, $cwd = null)
    {
        $process = null;
        $pipes = array();
        $out = '';
        $status = null;

        if($cmd !== null)
        {
            $process = proc_open(   escapeshellcmd($cmd),
                                    array(
                                        0 =&gt; array('pipe', 'r'),
                                        1 =&gt; array('pipe', 'w'),
                                        2 =&gt; array('pipe', 'w')
                                    ),
                                    $pipes,
                                    $cwd,
                                    $env
                                );

            if(is_resource($process))
            {
                usleep(1000);
                stream_set_write_buffer($pipes[1], 0);
                stream_set_write_buffer($pipes[2], 0);
                stream_set_timeout($pipes[1], 600);
                stream_set_timeout($pipes[2], 600);
                stream_set_blocking($pipes[0], false);
                stream_set_blocking($pipes[1], false);
                stream_set_blocking($pipes[2], false);

                if((bool)$output)
                {
                    while(!feof($pipes[2]))
                    {
                        $status = proc_get_status($process);
                        $out .= htmlspecialchars(fgets($pipes[2]), ENT_COMPAT, 'UTF-8');
                    }
                }else{
                    while(true)
                    {
                        $status = proc_get_status($process);
                        if((bool)$status['running'])
                        {
                            $out = true;
                            break;
                        }
                    }
                }

                fclose($pipes[0]);
                fclose($pipes[1]);
                fclose($pipes[2]);

                @proc_close($process);
                @exec('kill '.$status['pid'].' 2&gt;/dev/null &gt;&amp;- &gt;/dev/null');
                @clearstatcache();

                return $out;

            }else{
                 throw new PSOXException("invalid ressource - unable to open process for: $cmd");
            }
        }
    }

}</pre>
<div>Keeping all this in mind you can create a whole audio suite just with php. Imagine a step sequencer with a flash frontend which has a mp3 export function having you send an e-mail with your composition. Yes, &#8230; it works!</div>
<div id="seo_alrp_related"><h2>Posts Related to Process audio with PHP and Sox </h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/225/php-dom-xml-to-array" rel="bookmark">PHP DOM XML to Array</a></h3><p>What is the fastest way to parse a XML string into a equivalent valid Array representation? I have seen quite some efforts on different blogs ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf" rel="bookmark">PHP &#038; Ghostscript &#8211; Count pages of PDF</a></h3><p>Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe" rel="bookmark">MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</a></h3><p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/234/process-audio-with-php-and-sox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP DOM XML to Array</title>
		<link>http://set.cooki.me/archives/225/php-dom-xml-to-array</link>
		<comments>http://set.cooki.me/archives/225/php-dom-xml-to-array#comments</comments>
		<pubDate>Wed, 28 Sep 2011 12:18:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml to array]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=225</guid>
		<description><![CDATA[What is the fastest way to parse a XML string into a equivalent valid Array representation? I have seen quite some efforts on different blogs and the comments on php.net in some of the functions suggest some valid approaches. The problem with most approaches though, i find, is the lack of xml testing before passing [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What is the fastest way to parse a XML string into a equivalent valid Array representation?</strong></p>
<p>I have seen quite some efforts on different blogs and the comments on php.net in some of the functions suggest some valid approaches. The problem with most approaches though, i find, is the lack of xml testing before passing it to the function to transform the xml to array. When you want to make sure you have a valid XML string the PHP DOMDocument class and its sub classes provide everything for iteration through its childs, to saving string presentations to file and so on. On top DOM perfectly validates XML strings when passed into the loading methods of the class. Also i believe any approach using DOM rather then handling the XML string with regex or whatever should be much faster and safer to rely on.<br />
<span id="more-225"></span></p>
<p>After having validated the XML string, your XML to Array function should never throw any errors. So since you validated your XML with DOM you might as well make use of the DOM functions to transform your XML into Array; rather then only testing your XML string for validity. So here is a function i found a while ago (i dont remember where exactly so no credits :/) which i optimized a little to get rid of unwanted notices and also to make it more reliable:</p>
<pre class="brush: php; gutter: true; first-line: 1">function xmlToArray(DOMNode $node = null)
{
    $result = array();
    $group = array();
    $attrs = null;
    $children = null;

    if($node-&gt;hasAttributes())
    {
        $attrs = $node-&gt;attributes;
        foreach($attrs as $k =&gt; $v)
        {
            $result[$v-&gt;name] = $v-&gt;value;
        }
    }

    $children = $node-&gt;childNodes;

    if(!empty($children))
    {
        if((int)$children-&gt;length === 1)
        {
            $child = $children-&gt;item(0);

            if($child !== null &amp;&amp; $child-&gt;nodeType === XML_TEXT_NODE)
            {
                $result['#value'] = $child-&gt;nodeValue;
                if(count($result) == 1)
                {
                    return $result['#value'];
                }else{
                    return $result;
                }
            }
        }

        for($i = 0; $i &lt; (int)$children-&gt;length; $i++)
        {
            $child = $children-&gt;item($i);

            if($child !== null)
            {
                if(!isset($result[$child-&gt;nodeName]))
                {
                    $result[$child-&gt;nodeName] = xmlToArray($child);
                }else{
                    if(!isset($group[$child-&gt;nodeName]))
                    {
                        $result[$child-&gt;nodeName] = array($result[$child-&gt;nodeName]);
                        $group[$child-&gt;nodeName] = 1;
                    }
                    $result[$child-&gt;nodeName][] = xmlToArray($child);
                }
            }
        }
    }
    return $result;
}

$doc = DOMDocument::loadXML('your xml string');
$arr = xmlToArray($doc);
print_r($arr);</pre>
<p>If you want to have control over how the function deals with the value containing text nodes and attributes &#8211; looks for the attributes loop. You can alter it to the way you like. In the current form it will, once there is a node attribute, return a associative Array with attribute name =&gt; attribute value pairs and the actually text node value as #value key. If you always check for arrays, in the lowest depth where you will expect the node values, you should do fine.</p>
<div id="seo_alrp_related"><h2>Posts Related to PHP DOM XML to Array</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf" rel="bookmark">PHP &#038; Ghostscript &#8211; Count pages of PDF</a></h3><p>Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/256/wp-simpledesign-amazon-s3-tweak" rel="bookmark">WP SimpleDesign multi instance Amazon S3 Player Tweak</a></h3><p>The iSimpleDesign Amazon S3 Player lets you access your S3 Account to playback your .mp3 files with the AS3 Flash Dewplayer. See (http://wordpress.org/extend/plugins/isimpledesign-amazon-s3-music-player-plugin/) for more. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe" rel="bookmark">MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</a></h3><p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/225/php-dom-xml-to-array/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &amp; Ghostscript &#8211; Count pages of PDF</title>
		<link>http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf</link>
		<comments>http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf#comments</comments>
		<pubDate>Sat, 10 Sep 2011 15:55:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[ghostscript]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://set.cooki.me/?p=184</guid>
		<description><![CDATA[Count pages of a pdf is pretty simple! One way of finding out how to count the pages of a PDF file with PHP apart from imagemagick which always performance very slow and shaky (depends on the version) is to use the Linux Ghostscript library via shell and PHPs exec() commands. //$pdf full path to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Count pages of a pdf is pretty simple!</strong></p>
<p>One way of finding out how to count the pages of a PDF file with PHP apart from imagemagick which always performance very slow and shaky (depends on the version) is to use the Linux Ghostscript library via shell and PHPs exec() commands.<span id="more-184"></span></p>
<pre class="brush: php; gutter: true; first-line: 1">//$pdf full path to pdf file
function countPages($pdf = null)
{
    if($pdf !== null)
    {
        $c = "gs " . @escapeshellcmd("-q -sPDFname=".$pdf." ".rtrim(dirname(__FILE__), "/")."/counter.ps");
        @exec($c, $r);
        if(stristr($r[0], "error") === false)
        {
            if((bool)preg_match("/\%\%Pages\:\s+([0-9]{1,})/i", $r[0], $m))
            {
                return (int)$m[1];
            }
        }else{
            throw new Exception($r[0]);
        }
    }
}</pre>
<p>Just make sure Ghostscript is installed and configured right and executable from bash and you have the counter.ps postscript file in the same directory from where you call the script. The content of the .ps file looks like. I found it on some other page but cannot remember where exactly so credits to unknown:</p>
<pre class="brush: bash; gutter: true; first-line: 1">% pdfpagecount.ps
% read pdf file and output number of pages
% based on pdf2dsc.ps with one line taken from ps2ascii.ps
/PDFfile PDFname (r) file def 

/PageCountString 255 string 

def
systemdict /.setsafe known { .setsafe } if
/.show.stdout { (%stdout) (w) file } bind def
/puts { .show.stdout exch writestring } bind def
GS_PDF_ProcSet begin
pdfdict begin
PDFfile
pdfopen begin
/FirstPage where { pop } { /FirstPage 1 def } ifelse
/LastPage where { pop } { /LastPage pdfpagecount def } ifelse
(%%Pages: ) puts
LastPage FirstPage sub 1 add 

PageCountString cvs puts 

quit</pre>
<p>Just parse the result with regular expressions for the line with &#8220;Pages&#8221; and you have the number of pages of your PDF file. I have tried it with different PDF version and standards and so far the results have been all correct.</p>
<div id="seo_alrp_related"><h2>Posts Related to PHP & Ghostscript - Count pages of PDF</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/225/php-dom-xml-to-array" rel="bookmark">PHP DOM XML to Array</a></h3><p>What is the fastest way to parse a XML string into a equivalent valid Array representation? I have seen quite some efforts on different blogs ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/281/phpxml-based-staging-script" rel="bookmark">PHP/XML based staging script</a></h3><p>There are many software clients that let you sync content from your local environment to a remote server via (s)ftp but what to do if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/234/process-audio-with-php-and-sox" rel="bookmark">Process audio with PHP and Sox</a></h3><p>You want to mix/merge/edit audio file only with php on-the-fly? export your mix to mp3 ... thinks its not possible? Well it is! This will ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/248/get-bookmarks-from-pdf-with-php" rel="bookmark">Get bookmarks from PDF with PHP</a></h3><p>Splitting a PDF according to its Table of Content (Bookmarks) with PHP by using the linux lib http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ you can use the following command to write a ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://set.cooki.me/archives/268/mysql-backup-with-7-zip-and-aespipe" rel="bookmark">MySQL Backups &#8211; 7-zip protected AES 256 Bit encrypted</a></h3><p>Making MySql Backups is a crucial thing and should be done automatically by some routine rather then people doing it by hand. Doing the backup ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://set.cooki.me/archives/184/php-ghostscript-count-pages-of-pdf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

