<?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>Autarchy of the Private CavePHP &#187;</title> <atom:link href="http://bogdan.org.ua/categories/programming/php/feed" rel="self" type="application/rss+xml" /><link>http://bogdan.org.ua</link> <description>Tiny bits of bioinformatics, [web-]programming etc</description> <lastBuildDate>Tue, 15 May 2012 21:56:55 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Configuring web-server: for production and for development</title><link>http://bogdan.org.ua/2009/10/25/configuring-web-server-for-production-and-for-development.html</link> <comments>http://bogdan.org.ua/2009/10/25/configuring-web-server-for-production-and-for-development.html#comments</comments> <pubDate>Sun, 25 Oct 2009 15:16:10 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[development]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[production]]></category> <category><![CDATA[web-server]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=680</guid> <description><![CDATA[Production: see http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-debian-etch &#8211; it is for Debian Etch (which is old-stable), but many of the steps apply equally well to Debian Lenny (current-stable). Also, this is a very basic guide, as if you are going to host multiple sites from multiple clients, you most definitely will need some hosting control panel. Development: see http://www.ruzee.com/blog/2009/01/apache-virtual-hosts-a-clean-setup-for-php-developers. [...]]]></description> <content:encoded><![CDATA[<p><strong>Production</strong>: see <a
href="http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-debian-etch" rel="nofollow" >http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-debian-etch</a> &#8211; it is for Debian Etch (which is old-stable), but many of the steps apply equally well to Debian Lenny (current-stable). Also, this is a very basic guide, as if you are going to host multiple sites from multiple clients, you most definitely will need some <a
href="http://bogdan.org.ua/2008/09/27/which-hosting-control-panel-to-use-for-a-debian-server.html">hosting control panel</a>.</p><p><strong>Development</strong>: see <a
href="http://www.ruzee.com/blog/2009/01/apache-virtual-hosts-a-clean-setup-for-php-developers" rel="nofollow" >http://www.ruzee.com/blog/2009/01/apache-virtual-hosts-a-clean-setup-for-php-developers</a>. This setup works very well, unless you need to create several virtual hosts every day &#8211; in which case necessary actions could be partially scripted.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2009/10/25/configuring-web-server-for-production-and-for-development.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2009/10/25/configuring-web-server-for-production-and-for-development.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2009%2F10%2F25%2Fconfiguring-web-server-for-production-and-for-development.html&amp;title=Configuring%20web-server%3A%20for%20production%20and%20for%20development" id="wpa2a_4"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2009/10/25/configuring-web-server-for-production-and-for-development.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Debugging PHP: Eclipse PDT + XDebug + XDebug helper</title><link>http://bogdan.org.ua/2009/06/08/debugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html</link> <comments>http://bogdan.org.ua/2009/06/08/debugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html#comments</comments> <pubDate>Sun, 07 Jun 2009 22:59:43 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[bug]]></category> <category><![CDATA[debugging]]></category> <category><![CDATA[development]]></category> <category><![CDATA[Eclipse]]></category> <category><![CDATA[FireFox]]></category> <category><![CDATA[PDT]]></category> <category><![CDATA[xdebug]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=735</guid> <description><![CDATA[Stimulated by a bug in a complex and unfamiliar web PHP application with heaps of custom tweaks by other programmers, I decided to try a more professional approach to PHP programming and debugging than the standard var_dump() and family. As a result, I&#8217;m now using Eclipse PDT with Xdebug and Xdebug Helper (Firefox extension). Now [...]]]></description> <content:encoded><![CDATA[<p>Stimulated by a bug in a complex and unfamiliar web PHP application with heaps of custom tweaks by other programmers, I decided to try a more professional approach to PHP programming and debugging than the standard var_dump() and family.</p><p>As a result, I&#8217;m now using Eclipse <abbr
title="PHP Development Tools">PDT</abbr> with <a
href="http://xdebug.org/" rel="nofollow" >Xdebug</a> and <a
href="https://addons.mozilla.org/uk/firefox/addon/3960" rel="nofollow" >Xdebug Helper</a> (Firefox extension). Now I don&#8217;t understand how I used to debug my PHP programs before!</p><p>After proper configuration (I&#8217;m using local Apache, but it is also possible to debug remotely), my work flow is rather simple:</p><ul><li>use my web-app as usual, e.g. tweaking and testing here and there</li><li>if something server-side goes wrong: click the <a
href="https://addons.mozilla.org/uk/firefox/addon/3960" rel="nofollow" >XDebug helper</a> icon in Firefox, and perform some server-request action (e.g. load a page)</li><li>debugging is started in Eclipse PDT, where I can step through the code, set breakpoints, and examine all variables</li><li>as soon as the problem is fixed &#8211; click the XDebug helper icon again to continue using the site normally (w/o invoking the debugger)</li></ul><p>It takes some time to get used to, but then it&#8217;s a breeze.</p><p>Some advice:</p><ul><li>don&#8217;t use apt-get/aptitude to install Eclipse; it will be much easier both in the short and long run to use some all-in-one package from the <a
href="http://www.eclipse.org/pdt/downloads/" rel="nofollow" >Eclipse PDT site</a>; all you need to do &#8211; download, extract, run!</li><li>before actually starting to do anything, tweak the eclipse.ini file by increasing heap size from 40 MiB (default) to some larger value (I used 128MiB). If you don&#8217;t do this, then at some point your debugging will become painfully sloooow, and then you&#8217;ll start getting tons of &#8220;out of heap memory&#8221; errors, each one suggesting that you quit Eclipse immediately</li><li>install <a
href="http://xdebug.org/" rel="nofollow" >XDebug</a> with apt-get/aptitude &#8211; worked perfectly, and there&#8217;s /etc/php5/conf.d/xdebug.ini not to mess with php.ini</li><li>do <strong>read</strong> <a
href="http://www.eclipse.org/pdt/documents/XDebugGuideForPDT2.0.pdf" rel="nofollow" >XDebug guide for PDT 2.x</a> (I&#8217;m assuming you got the 2.x version); it should be the only document you will really need to configure everything</li></ul><p>I only wish Eclipse was faster &#8211; that is, written not in Java but e.g. C or C++.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2009/06/08/debugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2009/06/08/debugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2009%2F06%2F08%2Fdebugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html&amp;title=Debugging%20PHP%3A%20Eclipse%20PDT%20%2B%20XDebug%20%2B%20XDebug%20helper" id="wpa2a_8"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2009/06/08/debugging-php-like-a-pro-eclipse-pdt-xdebug-helper.html/feed</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>WordPress and Google Analytics external nofollow problem in comment links</title><link>http://bogdan.org.ua/2009/02/13/wordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html</link> <comments>http://bogdan.org.ua/2009/02/13/wordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html#comments</comments> <pubDate>Fri, 13 Feb 2009 19:41:55 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[CMS]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[comment]]></category> <category><![CDATA[fix]]></category> <category><![CDATA[link]]></category> <category><![CDATA[problem]]></category> <category><![CDATA[wordpress]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=594</guid> <description><![CDATA[Since some WP release, the comment author's link in comments is broken - it has ' external nofollow' attached straight to the href attribute (which breaks the link). I assume that the problem is caused by Google Analytics, namely the "track outgoing clicks" feature (as recalled, might be inaccurate feature name). "Track outgoing links" adds [...]]]></description> <content:encoded><![CDATA[<p>Since some WP release, the comment author's link in comments is broken - it has ' external nofollow' attached straight to the href attribute (which breaks the link).</p><p>I assume that the problem is caused by Google Analytics, namely the "track outgoing clicks" feature (as recalled, might be inaccurate feature name). "Track outgoing links" adds some JavaScript code to all outgoing links, and that script has tick characters like this one ' which, incidentally, are also used for delimiting the values of comment anchor tags.</p><p>To fix:<br
/> <span
id="more-594"></span></p><ol><li>locate file <strong>wp-includes/comment-template.php</strong></li><li>in that file, find the <strong>get_comment_author_link</strong> function (lines 140-150 in WP 2.7.1)</li><li>replace the line<div
class="igBar"><span
id="lphp-3"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-3'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-3"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$return</span> = <span
style="color:#FF0000;">"&lt;a href='$url' rel='external nofollow' class='url'&gt;$author&lt;/a&gt;"</span>;</div></li></ol></div></div></div><p> with</p><div
class="igBar"><span
id="lphp-4"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-4"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$return</span> = <span
style="color:#FF0000;">'&lt;a href=&quot;'</span>.<span
style="color:#0000FF;">$url</span>.<span
style="color:#FF0000;">'&quot; rel=&quot;external nofollow&quot; class=&quot;url&quot;&gt;'</span>.<span
style="color:#0000FF;">$author</span>.<span
style="color:#FF0000;">'&lt;/a&gt;'</span>;</div></li></ol></div></div></div><p></li></ol><p>This helped me and might help you.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2009/02/13/wordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2009/02/13/wordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2009%2F02%2F13%2Fwordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html&amp;title=WordPress%20and%20Google%20Analytics%20external%20nofollow%20problem%20in%20comment%20links" id="wpa2a_12"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2009/02/13/wordpress-and-google-analytics-external-nofollow-problem-in-comment-links.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>ExpressionEngine contact form (email module) spam vulnerability</title><link>http://bogdan.org.ua/2009/01/26/expressionengine-contact-form-email-module-spam-vulnerability.html</link> <comments>http://bogdan.org.ua/2009/01/26/expressionengine-contact-form-email-module-spam-vulnerability.html#comments</comments> <pubDate>Mon, 26 Jan 2009 09:50:05 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[CMS]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[EE]]></category> <category><![CDATA[ExpressionEngine]]></category> <category><![CDATA[spam]]></category> <category><![CDATA[vulnerability]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/?p=575</guid> <description><![CDATA[Yesterday I had a look at mod.email.php - the Email module of ExpressionEngine CMS. It appears that it is very easy to use ExpressionEngine's contact form (which uses Email module) to send emails to arbitrary addresses - simply put, send spam using someone's EE. And here's why: recipients hidden field is passed to the client; [...]]]></description> <content:encoded><![CDATA[<p>Yesterday I had a look at mod.email.php - the Email module of ExpressionEngine CMS.</p><p>It appears that it is very easy to use ExpressionEngine's contact form (which uses Email module) to send emails to arbitrary addresses - simply put, send spam using someone's EE.</p><p>And here's why:</p><ul><li><em>recipients</em> hidden field is passed to the client; it is encrypted, but with access to the mod.email.php code, it is a matter of several minutes to write your own email-encoding function which will produce a completely valid <em>recipients</em> field</li><li>there's also <em>XID</em> field, which seems to be unique for each page load</li></ul><p>Spamming algorithm is clear, so I won't elaborate. (I could have missed some session variables, though - didn't check them.)</p><p>This information is valid as of ExpressionEngine 1.6.6, but nothing in the change-logs indicates that this mechanism was modified in the newer versions of EE.</p><p><ins
datetime="2009-01-26T13:12:42+00:00">Update:</ins> I've tested, and this vulnerability does exist. The simplest prevention measure is to enable Captcha for Contact Form.</p><p>I've <a
href="http://expressionengine.com/archived_forums/viewthread/103537/" rel="nofollow" >notified</a> the developers.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2009/01/26/expressionengine-contact-form-email-module-spam-vulnerability.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2009/01/26/expressionengine-contact-form-email-module-spam-vulnerability.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2009%2F01%2F26%2Fexpressionengine-contact-form-email-module-spam-vulnerability.html&amp;title=ExpressionEngine%20contact%20form%20%28email%20module%29%20spam%20vulnerability" id="wpa2a_16"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2009/01/26/expressionengine-contact-form-email-module-spam-vulnerability.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Instructions on installing libmp3lame-enabled ffmpeg on shared linux hosting</title><link>http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html</link> <comments>http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html#comments</comments> <pubDate>Wed, 12 Mar 2008 06:25:54 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[*nix]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[ffmpeg]]></category> <category><![CDATA[install]]></category> <category><![CDATA[libmp3lame]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[shared hosting]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html</guid> <description><![CDATA[Note: this post is based on the comment by Simon, who generously shared his experience. Step-by-step: Download the compiled ffmpeg with libmp3lame support (direct download links: older version ffmpeg.with.lame and newer version ffmpeg.2007-10-28.with-libmp3lame-support). Rename the downloaded executable file to "ffmpeg" (no extension), upload it to the directory on your server (in this example /home/myusername/). Download [...]]]></description> <content:encoded><![CDATA[<p><em>Note:</em> this post is based on the <a
href="http://bogdan.org.ua/2007/10/25/using-libmp3lame-enabled-ffmpeg-on-shared-hosting.html#comment-59670">comment by Simon</a>, who generously shared his experience.</p><p>Step-by-step:</p><ul><li>Download the <a
href="http://bogdan.org.ua/2007/06/28/compiled-linux-ffmpeg-binary-for-gallery2-download.html"title="this page will be irregularly updated with new compiled binaries of ffmpeg" >compiled ffmpeg with libmp3lame support</a> (direct download links: older version <a
href="http://bogdan.org.ua/wp-content/uploads/2007/06/ffmpeg.with.lame">ffmpeg.with.lame</a> and newer version <a
href="http://bogdan.org.ua/wp-content/uploads/2007/10/ffmpeg.2007-10-28.with-libmp3lame-support">ffmpeg.2007-10-28.with-libmp3lame-support</a>).</li><li>Rename the downloaded executable file to "ffmpeg" (no extension), upload it to the directory on your server (in this example /home/myusername/).</li><li>Download <a
href="http://bogdan.org.ua/wp-content/uploads/2008/03/libmp3lame.so.0">libmp3lame.so.0</a>.</li><li>Upload libmp3lame.so.0 to the same directory where you placed ffmpeg in.</li><li>Create a php file with the following code (remember to change the paths to your own, where you actually uploaded binaries in previous steps):<div
class="igBar"><span
id="lphp-7"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-7'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-7"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">&lt;?php</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/exec" rel="nofollow" ><span
style="color:#000066;">exec</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"export LD_LIBRARY_PATH=/home/myusername/"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <a
href="http://www.php.net/passthru" rel="nofollow" ><span
style="color:#000066;">passthru</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"/home/myusername/ffmpeg -formats"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">?&gt;</span></div></li></ol></div></div></div><p></li><li>If you access that PHP file with your browser, you should be able to see a list of formats which are supported by ffmpeg, and if you find "EA libmp3lame" somewhere in the output, then it means you now can Encode Audio in libmp3lame!</li><li>If that doesn't work for you: LD_LIBRARY_PATH can be a protected variable in PHP (you can check for this by searching for the "safe_mode_protected_env_vars" value in phpinfo() output). The workaround here can be to write your commands to a file from php, then <strong>chmod</strong> that file with 0755 permissions (rwx-rx-rx), and run the file through <strong>exec()</strong>. In this way, PHP is not changing the LD_LIBRARY_PATH, but telling the server to run a file, which tells the server to change it. This method worked for the original author of these instructions.</li></ul><p>For passing arguments to the PHP wrapper script - check out PHP's $argv variable (more on this <a
href="http://www.php.net/features.commandline" rel="nofollow" >here</a>). If you decided to use shell-script as a wrapper for "export LD_LIBRARY_PATH", then using $1, $2 etc will allow you to pass parameters to the shell script, e.g. in the example below</p><div
class="igBar"><span
id="lcode-8"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('code-8'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-8"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">#!/bin/bash</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">export LD_LIBRARY_PATH=/home/myusername/</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">/home/myusername/ffmpeg -i /home/myusername/$<span
style="color:#800000;color:#800000;">1</span> $<span
style="color:#800000;color:#800000;">2</span> /home/myusername/$<span
style="color:#800000;color:#800000;">3</span></div></li></ol></div></div></div><p> you could pass "input file" as first argument, "parameters" as second and "output file" as third to make such a wrapper script work.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2008%2F03%2F12%2Finstructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html&amp;title=Instructions%20on%20installing%20libmp3lame-enabled%20ffmpeg%20on%20shared%20linux%20hosting" id="wpa2a_20"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2008/03/12/instructions-on-installing-libmp3lame-enabled-ffmpeg-on-shared-linux-hosting.html/feed</wfw:commentRss> <slash:comments>16</slash:comments> </item> <item><title>Convert MySQL database from one encoding/collation into another</title><link>http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html</link> <comments>http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html#comments</comments> <pubDate>Fri, 08 Feb 2008 19:17:45 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[collation]]></category> <category><![CDATA[convert]]></category> <category><![CDATA[database]]></category> <category><![CDATA[encoding]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[latin1]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[script]]></category> <category><![CDATA[utf8]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html</guid> <description><![CDATA[Most frequent use: convert database from latin1_swedish to utf8_general_ci. Original script found at: MySQL and UTF-8. Update: the original script had an error, it would generate queries likes this one (note the bold part): ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT NULL; This is clearly wrong syntax [...]]]></description> <content:encoded><![CDATA[<p>Most frequent use: <a
href="http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html"title="self-link" >convert database from latin1_swedish to utf8_general_ci</a>.<br
/> Original script found at: <a
href="http://www.phpwact.org/php/i18n/utf-8/mysql" rel="nofollow" >MySQL and UTF-8</a>.</p><p><ins
datetime="2008-02-22T21:50:28+00:00">Update:</ins> the original script <u>had an error</u>, it would generate queries likes this one (note the bold part):</p><blockquote><p>ALTER TABLE `links` CHANGE `link_rel` `link_rel` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci <strong>NOT NULL  DEFAULT NULL</strong>;</p></blockquote><p>This is clearly wrong syntax (and logic). I fixed this by making comparison to NULL strict (with three equal signs instead of two):</p><blockquote><p> // Does the field default to null, a string, or nothing?<br
/> if ($row['Default'] === NULL)</p></blockquote><p><ins
datetime="2008-06-27T07:23:50+00:00">Update 2:</ins> based on comment by <em>banesto</em>, I modified the script; now it does not require specifying the from_collation, it's sufficient to specify to_collation (which will be used for all the fields and tables). The modified code is:</p><blockquote><p>if ($row['Collation'] == '' || $row['Collation'] == $convert_to)<br
/> continue;</p></blockquote><p><ins
datetime="2010-06-28T11:58:11+00:00">Update 3:</ins> the long-lasting, re-appearing NOT NULL DEFAULT NULL problem is finally fixed.</p><p><ins
datetime="2010-06-28T12:11:38+00:00">Update 4:</ins> incorporated Russ's fix to skip numeric fields (in order to leave autoincrement values intact).</p><p>Here's the script itself: (to copy-paste: first click the "Plain text" header)<br
/> <span
id="more-255"></span></p><div
class="igBar"><span
id="lphp-10"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-10"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">&lt;?php</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// Original script (v1.0) by/from: http://www.phpwact.org/php/i18n/utf-8/mysql</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// Improved/modified (v1.05) by Bogdan http://bogdan.org.ua/</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// Last updated: 2010-06-28</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// this script will output all queries needed to change all fields/tables to a different collation</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// it is HIGHLY suggested you make a MySQL backup prior to running any of the generated queries</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// this code is provided AS IS and without any warranty</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// add text/plain header when used not as a CLI script; PHP CLI SAPI shouldn't output headers</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Content-Type: text/plain"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// precaution</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/die" rel="nofollow" ><span
style="color:#000066;">die</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Make a backup of your MySQL database, then remove this line from the code!"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/set_time_limit" rel="nofollow" ><span
style="color:#000066;">set_time_limit</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#CC66CC;color:#800000;">0</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// collation you want to change to:</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$convert_to</span>&nbsp; &nbsp;= <span
style="color:#FF0000;">'utf8_general_ci'</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// character set of new collation:</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$character_set</span>= <span
style="color:#FF0000;">'utf8'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// DB login information - *modify before use*</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$username</span> = <span
style="color:#FF0000;">'user'</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$password</span> = <span
style="color:#FF0000;">'pass'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$database</span> = <span
style="color:#FF0000;">'database_name'</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$host</span>&nbsp; &nbsp; &nbsp;= <span
style="color:#FF0000;">'localhost'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">//-- usually, there is nothing to modify below this line --//</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// show TABLE alteration queries?</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$show_alter_table</span> = <span
style="color:#000000; font-weight:bold;">true</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// show FIELD alteration queries?</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$show_alter_field</span> = <span
style="color:#000000; font-weight:bold;">true</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/mysql_connect" rel="nofollow" ><span
style="color:#000066;">mysql_connect</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$host</span>, <span
style="color:#0000FF;">$username</span>, <span
style="color:#0000FF;">$password</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/mysql_select_db" rel="nofollow" ><span
style="color:#000066;">mysql_select_db</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$database</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$rs_tables</span> = <a
href="http://www.php.net/mysql_query" rel="nofollow" ><span
style="color:#000066;">mysql_query</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">" SHOW TABLES "</span><span
style="color:#006600; font-weight:bold;">&#41;</span> or <a
href="http://www.php.net/die" rel="nofollow" ><span
style="color:#000066;">die</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/mysql_error" rel="nofollow" ><span
style="color:#000066;">mysql_error</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#616100;">while</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row_tables</span> = <a
href="http://www.php.net/mysql_fetch_row" rel="nofollow" ><span
style="color:#000066;">mysql_fetch_row</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$rs_tables</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$table</span> = <a
href="http://www.php.net/mysql_real_escape_string" rel="nofollow" ><span
style="color:#000066;">mysql_real_escape_string</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row_tables</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#CC66CC;color:#800000;">0</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Alter table collation</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// ALTER TABLE `account` DEFAULT CHARACTER SET utf8</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$show_alter_table</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"ALTER TABLE `$table` DEFAULT CHARACTER SET $character_set;<span
style="color:#000099; font-weight:bold;">\n</span>"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$rs</span> = <a
href="http://www.php.net/mysql_query" rel="nofollow" ><span
style="color:#000066;">mysql_query</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">" SHOW FULL FIELDS FROM `$table` "</span><span
style="color:#006600; font-weight:bold;">&#41;</span> or <a
href="http://www.php.net/die" rel="nofollow" ><span
style="color:#000066;">die</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/mysql_error" rel="nofollow" ><span
style="color:#000066;">mysql_error</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">while</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$row</span> = <a
href="http://www.php.net/mysql_fetch_assoc" rel="nofollow" ><span
style="color:#000066;">mysql_fetch_assoc</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$rs</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Collation'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#FF0000;">''</span> || <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Collation'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#0000FF;">$convert_to</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">continue</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Is the field allowed to be null?</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Null'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#FF0000;">'YES'</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$nullable</span> = <span
style="color:#FF0000;">' NULL '</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">else</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$nullable</span> = <span
style="color:#FF0000;">' NOT NULL '</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Does the field default to null, a string, or nothing?</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Default'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> === <span
style="color:#000000; font-weight:bold;">NULL</span> &amp;&amp; <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Null'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#FF0000;">'YES'</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$default</span> = <span
style="color:#FF0000;">" DEFAULT NULL "</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">elseif</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Default'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> != <span
style="color:#FF0000;">''</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$default</span> = <span
style="color:#FF0000;">" DEFAULT '"</span>.<a
href="http://www.php.net/mysql_real_escape_string" rel="nofollow" ><span
style="color:#000066;">mysql_real_escape_string</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Default'</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>.<span
style="color:#FF0000;">"'"</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">else</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$default</span> = <span
style="color:#FF0000;">''</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// sanity check and fix:</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$nullable</span> == <span
style="color:#FF0000;">' NOT NULL '</span> &amp;&amp; <span
style="color:#0000FF;">$default</span> == <span
style="color:#FF0000;">' DEFAULT NULL '</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$default</span> = <span
style="color:#FF0000;">''</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <span
style="color:#FF0000;">"/* Warning: wrong combination of 'default value' and 'NULL-flag' detected - and fixed! */<span
style="color:#000099; font-weight:bold;">\n</span>"</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <span
style="color:#FF0000;">"/* Diagnostics: row[Null] = '$row[Null]', row[Default] = "</span> . <a
href="http://www.php.net/mysql_real_escape_string" rel="nofollow" ><span
style="color:#000066;">mysql_real_escape_string</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Default'</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span> . <span
style="color:#FF0000;">", MySQL version: "</span> . <a
href="http://www.php.net/mysql_get_server_info" rel="nofollow" ><span
style="color:#000066;">mysql_get_server_info</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span> . <span
style="color:#FF0000;">" */<span
style="color:#000099; font-weight:bold;">\n</span>"</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Don't alter INT columns: no collations, and altering them drops autoincrement values</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/strpos" rel="nofollow" ><span
style="color:#000066;">strpos</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Type'</span><span
style="color:#006600; font-weight:bold;">&#93;</span>, <span
style="color:#FF0000;">'int'</span><span
style="color:#006600; font-weight:bold;">&#41;</span> !== <span
style="color:#000000; font-weight:bold;">false</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$show_alter_field</span> = <span
style="color:#000000; font-weight:bold;">False</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">else</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$show_alter_field</span> = <span
style="color:#000000; font-weight:bold;">True</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Alter field collation:</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// ALTER TABLE `tab` CHANGE `field` `field` CHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$show_alter_field</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$field</span> = <a
href="http://www.php.net/mysql_real_escape_string" rel="nofollow" ><span
style="color:#000066;">mysql_real_escape_string</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$row</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'Field'</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <span
style="color:#FF0000;">"ALTER TABLE `$table` CHANGE `$field` `$field` $row[Type] CHARACTER SET $character_set COLLATE $convert_to $nullable $default;<span
style="color:#000099; font-weight:bold;">\n</span>"</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">?&gt;</span></div></li></ol></div></div></div><p></p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2008%2F02%2F08%2Fconvert-mysql-database-from-one-encodingcollation-into-another.html&amp;title=Convert%20MySQL%20database%20from%20one%20encoding%2Fcollation%20into%20another" id="wpa2a_24"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2008/02/08/convert-mysql-database-from-one-encodingcollation-into-another.html/feed</wfw:commentRss> <slash:comments>57</slash:comments> </item> <item><title>PHP proxy</title><link>http://bogdan.org.ua/2007/09/19/php-proxy.html</link> <comments>http://bogdan.org.ua/2007/09/19/php-proxy.html#comments</comments> <pubDate>Wed, 19 Sep 2007 16:41:35 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[Notepad]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/09/19/php-proxy.html</guid> <description><![CDATA[PHP proxy is simple but good. I converted it into a proxy-function for one of my projects. Do pay attention to the comments, especially these two: I had issues with this script (and others) returning 0 for the bytesTotal in flash. Basically, the Content-Length header was absent from the response. By simply adding header("Content-length: ".strlen($response)) [...]]]></description> <content:encoded><![CDATA[<p><a
href="http://www.abdulqabiz.com/blog/archives/2007/05/31/php-proxy-script-for-cross-domain-requests/" rel="nofollow" >PHP proxy</a> is simple but good. I converted it into a proxy-function for one of my projects.</p><p>Do pay attention to the comments, especially these two:</p><blockquote><p> I had issues with this script (and others) returning 0 for the bytesTotal in flash. Basically, the Content-Length header was absent from the response. By simply adding<br
/> header("Content-length: ".strlen($response)) before the echo, it resolved the issue. I don't know if there is a more appropriate fix to account for character encoding, etc, but it seems to work.</p></blockquote><blockquote><p> @Schimmi: Well, if you can add some checks there (like who is referring your script) and allow the access to whitelisted clients (served from your domain)... I think, you can totally make it used applications from same-domain....So it would not be open to world. Yeah above script doesn't have those things.</p></blockquote><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/09/19/php-proxy.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/09/19/php-proxy.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F09%2F19%2Fphp-proxy.html&amp;title=PHP%20proxy" id="wpa2a_28"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/09/19/php-proxy.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to convert between utf8 and cp-1251 without iconv or mbstring</title><link>http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html</link> <comments>http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html#comments</comments> <pubDate>Sun, 08 Jul 2007 14:32:57 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html</guid> <description><![CDATA[This helped me, maybe it will help you: How to convert between utf8 and cp1251 without iconv In case the original disappears, here's a "backup": PLAIN TEXT PHP: function cp1251_to_utf8&#40;$s&#41;&#123; &#160; &#160; $c209 = chr&#40;209&#41;; $c208 = chr&#40;208&#41;; $c129 = chr&#40;129&#41;; &#160; &#160; for&#40;$i=0; $i&#60;strlen&#40;$s&#41;; $i++&#41;&#160; &#160; &#123; &#160; &#160; &#160; &#160; $c=ord&#40;$s&#91;$i&#93;&#41;; &#160; &#160; [...]]]></description> <content:encoded><![CDATA[<p>This helped me, maybe it will help you: <a
href="http://www.ustrem.org/en/articles/how-to-convert-between-utf8-cp1251-without-iconv-en/" rel="nofollow" >How to convert between utf8 and cp1251 without iconv</a><br
/> <span
id="more-195"></span></p><p>In case the original disappears, here's a "backup":</p><div
class="igBar"><span
id="lphp-12"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-12'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-12"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> cp1251_to_utf8<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$c209</span> = <a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#CC66CC;color:#800000;">209</span><span
style="color:#006600; font-weight:bold;">&#41;</span>; <span
style="color:#0000FF;">$c208</span> = <a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#CC66CC;color:#800000;">208</span><span
style="color:#006600; font-weight:bold;">&#41;</span>; <span
style="color:#0000FF;">$c129</span> = <a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#CC66CC;color:#800000;">129</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">for</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$i</span>=<span
style="color:#CC66CC;color:#800000;">0</span>; <span
style="color:#0000FF;">$i</span>&lt;strlen<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#41;</span>; <span
style="color:#0000FF;">$i</span>++<span
style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$c</span>=<a
href="http://www.php.net/ord" rel="nofollow" ><span
style="color:#000066;">ord</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#0000FF;">$i</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>&gt;=<span
style="color:#CC66CC;color:#800000;">192</span> and <span
style="color:#0000FF;">$c</span>&lt;=<span
style="color:#CC66CC;color:#800000;">239</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#0000FF;">$t</span>.=<span
style="color:#0000FF;">$c208</span>.<a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>-<span
style="color:#CC66CC;color:#800000;">48</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">elseif</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>&gt;<span
style="color:#CC66CC;color:#800000;">239</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#0000FF;">$t</span>.=<span
style="color:#0000FF;">$c209</span>.<a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>-<span
style="color:#CC66CC;color:#800000;">112</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">elseif</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>==<span
style="color:#CC66CC;color:#800000;">184</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#0000FF;">$t</span>.=<span
style="color:#0000FF;">$c209</span>.<span
style="color:#0000FF;">$c209</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">elseif</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>==<span
style="color:#CC66CC;color:#800000;">168</span><span
style="color:#006600; font-weight:bold;">&#41;</span>&nbsp; &nbsp; <span
style="color:#0000FF;">$t</span>.=<span
style="color:#0000FF;">$c208</span>.<span
style="color:#0000FF;">$c129</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">else</span> <span
style="color:#0000FF;">$t</span>.=<span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#0000FF;">$i</span><span
style="color:#006600; font-weight:bold;">&#93;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">return</span> <span
style="color:#0000FF;">$t</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> utf8_to_cp1251<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">for</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c</span>=<span
style="color:#CC66CC;color:#800000;">0</span>;<span
style="color:#0000FF;">$c</span>&lt;strlen<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;<span
style="color:#0000FF;">$c</span>++<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$i</span>=<a
href="http://www.php.net/ord" rel="nofollow" ><span
style="color:#000066;">ord</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#0000FF;">$c</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$i</span>&lt;=<span
style="color:#CC66CC;color:#800000;">127</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#0000FF;">$out</span>.=<span
style="color:#0000FF;">$s</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#0000FF;">$c</span><span
style="color:#006600; font-weight:bold;">&#93;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$byte2</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$new_c2</span>=<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c1</span>&amp;<span
style="color:#CC66CC;color:#800000;">3</span><span
style="color:#006600; font-weight:bold;">&#41;</span>*<span
style="color:#CC66CC;color:#800000;">64</span>+<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$i</span>&amp;<span
style="color:#CC66CC;color:#800000;">63</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$new_c1</span>=<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$c1</span>&gt;&gt;<span
style="color:#CC66CC;color:#800000;">2</span><span
style="color:#006600; font-weight:bold;">&#41;</span>&amp;<span
style="color:#CC66CC;color:#800000;">5</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$new_i</span>=<span
style="color:#0000FF;">$new_c1</span>*<span
style="color:#CC66CC;color:#800000;">256</span>+<span
style="color:#0000FF;">$new_c2</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$new_i</span>==<span
style="color:#CC66CC;color:#800000;">1025</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$out_i</span>=<span
style="color:#CC66CC;color:#800000;">168</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span> <span
style="color:#616100;">else</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$new_i</span>==<span
style="color:#CC66CC;color:#800000;">1105</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$out_i</span>=<span
style="color:#CC66CC;color:#800000;">184</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span> <span
style="color:#616100;">else</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$out_i</span>=<span
style="color:#0000FF;">$new_i</span>-<span
style="color:#CC66CC;color:#800000;">848</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$out</span>.=<a
href="http://www.php.net/chr" rel="nofollow" ><span
style="color:#000066;">chr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$out_i</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$byte2</span>=<span
style="color:#000000; font-weight:bold;">false</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$i</span>&gt;&gt;<span
style="color:#CC66CC;color:#800000;">5</span><span
style="color:#006600; font-weight:bold;">&#41;</span>==<span
style="color:#CC66CC;color:#800000;">6</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$c1</span>=<span
style="color:#0000FF;">$i</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#0000FF;">$byte2</span>=<span
style="color:#000000; font-weight:bold;">true</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">return</span> <span
style="color:#0000FF;">$out</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F07%2F08%2Fhow-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html&amp;title=How%20to%20convert%20between%20utf8%20and%20cp-1251%20without%20iconv%20or%20mbstring" id="wpa2a_32"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/07/08/how-to-convert-between-utf8-and-cp-1251-without-iconv-or-mbstring.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>How to make PEAR work from behind an HTTP proxy (Windows and Linux)</title><link>http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html</link> <comments>http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html#comments</comments> <pubDate>Thu, 31 May 2007 10:35:04 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Misc]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html</guid> <description><![CDATA[Earlier in one of my posts (Using PEAR HTTP_Client or HTTP_Request with HTTP proxy) I gave an example of using PEAR HTTP_Client and/or HTTP_Request from behind an http proxy. However, I didn't tell how to make PEAR itself work properly from behind an HTTP proxy (e.g., for online operations like "pear upgrade-all"). So here's that [...]]]></description> <content:encoded><![CDATA[<p>Earlier in one of my posts (<a
href="http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html">Using PEAR HTTP_Client or HTTP_Request with HTTP proxy</a>) I gave an example of using PEAR HTTP_Client and/or HTTP_Request from behind an http proxy. However, I didn't tell how to make PEAR itself work properly from behind an HTTP proxy (e.g., for online operations like "pear upgrade-all").</p><p>So here's that tiny missing bit of information.</p><p><strong>Windows:</strong><br
/> Launch <strong>regedit</strong>, navigate to <strong>HKEY_CURRENT_USER\Environment</strong>, and create a string value called <strong>PHP_PEAR_HTTP_PROXY</strong>. Modify that new value to hold the string like: <strong>http://proxy_username:proxy_password@proxy_server_address:proxy_port</strong>.</p><p><strong>Linux:</strong><br
/> In the Terminal/Konsole, execute (for a system-wide pear configuration)</p><blockquote><p>sudo pear config-set http_proxy http://proxy_username:proxy_password@proxy_server_address:proxy_port</p></blockquote><p>If your proxy password has symbols, special for the shell (e.g. question or exclamation mark) - enclose full proxy specifications with single-quotes, e.g.</p><blockquote><p>sudo pear config-set http_proxy 'http://proxy_username:proxy_password@proxy_server_address:proxy_port'</p></blockquote><p>If your HTTP proxy server does not require authentication, then use <strong>http://proxy_server_address:proxy_port</strong> instead.</p><p>I think the strings are completely self-explanatory; however, here's an example of proxy (with authentication) specification: http://john.smith:CrAzYP433WoRd@192.168.0.1:3128.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F05%2F31%2Fhow-to-make-pear-work-from-behind-an-http-proxy.html&amp;title=How%20to%20make%20PEAR%20work%20from%20behind%20an%20HTTP%20proxy%20%28Windows%20and%20Linux%29" id="wpa2a_36"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/05/31/how-to-make-pear-work-from-behind-an-http-proxy.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Directory-based random image rotation PHP script</title><link>http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html</link> <comments>http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html#comments</comments> <pubDate>Wed, 23 May 2007 15:23:15 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html</guid> <description><![CDATA[Yesterday I needed to put together a rather simple PHP script: it would read the contents of a single pre-configured directory, and randomly select up to a pre-configured number of files. These files were images, and were just dumped as IMG tags into the webpage. I came up with a solution, shown below. The script [...]]]></description> <content:encoded><![CDATA[<p>Yesterday I needed to put together a rather simple PHP script: it would read the contents of a single pre-configured directory, and randomly select up to a pre-configured number of files. These files were images, and were just dumped as IMG tags into the webpage. I came up with a solution, shown below.</p><p>The script is simple, but still it's easier to use the ready solution than to write your own <img
src='http://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .<br
/> It is heavily commented, and should be easy to understand.<br
/> <span
id="more-184"></span><br
/> <em>To copy-paste, first click the "PLAIN TEXT" box header.</em></p><div
class="igBar"><span
id="lphp-14"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-14'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-14"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// configuration</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// total number of images we want to display; can be 1 as well</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$to_display</span> = <span
style="color:#CC66CC;color:#800000;">10</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// type of files to use eg. .jpg or .gif or .png</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$file_types</span> = <a
href="http://www.php.net/array" rel="nofollow" ><span
style="color:#000066;">array</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">".jpg"</span>, <span
style="color:#FF0000;">".gif"</span>, <span
style="color:#FF0000;">".png"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// the location of the folder containing the images</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$image_folder</span> = <span
style="color:#FF0000;">"/usr/local/vhosts/sitename/htdocs/images"</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// URL prefix for all images' SRC attribute;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// can be just &quot;/&quot;, or full URL</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$URL_prefix</span> = <span
style="color:#FF0000;">"http://some-site.kiev.ua/images/"</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// no configuration below this comment!</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$Images</span> = <a
href="http://www.php.net/array" rel="nofollow" ><span
style="color:#000066;">array</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// check if $image_folder is really a directory</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/is_dir" rel="nofollow" ><span
style="color:#000066;">is_dir</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$image_folder</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#0000FF;">$handle</span> = <a
href="http://www.php.net/opendir" rel="nofollow" ><span
style="color:#000066;">opendir</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$image_folder</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#FF9933; font-style:italic;">// read *all* files from the $image_folder</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">while</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#000000; font-weight:bold;">false</span> !== <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$img</span> = <a
href="http://www.php.net/readdir" rel="nofollow" ><span
style="color:#000066;">readdir</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$handle</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#FF9933; font-style:italic;">// skip two &quot;special files&quot;,</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#FF9933; font-style:italic;">// current and upper directories</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$img</span> != <span
style="color:#FF0000;">"."</span> &amp;&amp; <span
style="color:#0000FF;">$img</span> != <span
style="color:#FF0000;">".."</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// extract file's extension and test if it</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// is present in the $file_types array;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// if yes - add file to the Images array</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span
style="color:#0000FF;">$typetest</span> = <a
href="http://www.php.net/strtolower" rel="nofollow" ><span
style="color:#000066;">strtolower</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/substr" rel="nofollow" ><span
style="color:#000066;">substr</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$img</span>,-<span
style="color:#CC66CC;color:#800000;">4</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <a
href="http://www.php.net/in_array" rel="nofollow" ><span
style="color:#000066;">in_array</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$typetest</span>, <span
style="color:#0000FF;">$file_types</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$Images</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#0000FF;">$img</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/closedir" rel="nofollow" ><span
style="color:#000066;">closedir</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$handle</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// if there are less images than $to_display,</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// decrease the number to actual</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <a
href="http://www.php.net/count" rel="nofollow" ><span
style="color:#000066;">count</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$Images</span><span
style="color:#006600; font-weight:bold;">&#41;</span> &lt;<span
style="color:#0000FF;">$to_display</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#0000FF;">$to_display</span> = <a
href="http://www.php.net/count" rel="nofollow" ><span
style="color:#000066;">count</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$Images</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// randomly select $to_display images</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$rand_keys</span> = <a
href="http://www.php.net/array_rand" rel="nofollow" ><span
style="color:#000066;">array_rand</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$Images</span>, <span
style="color:#0000FF;">$to_display</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// output IMG tags with random images</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#616100;">foreach</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$rand_keys</span> <span
style="color:#616100;">as</span> <span
style="color:#0000FF;">$rand_key</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <span
style="color:#FF0000;">'&lt;img src=&quot;'</span>.<span
style="color:#0000FF;">$URL_prefix</span>.<span
style="color:#0000FF;">$Images</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#0000FF;">$rand_key</span><span
style="color:#006600; font-weight:bold;">&#93;</span>.<span
style="color:#FF0000;">'&quot; alt=&quot;&quot; /&gt;'</span>;</div></li></ol></div></div></div><p></p><p>How to use: insert this code into your PHP file where you need to output the list of images. Do not forget to apply some pretty CSS styling to IMG tags! <img
src='http://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>The major drawback of this solution is inefficiency: reading the complete directory of image files on every page display is not good at all. However, I inserted this code snippet into the CMS's PHP-enabled template, which allows to turn on caching. This actually solves efficiency problem, as directory will be read (and images randomized...) only as often as long your configured cache is.</p><p>Another option is to add in some <a
href="http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html">caching options</a>. It might be reasonable as well to use MySQL HEAP-table (in-memory table) to store the directory-reading result and refresh it only once in an hour; this way images would be randomized on each page display, but the directory would be re-read less than once in an hour.</p><p>But all of the above-described enhancements are optional, and can be left as an exercise to the reader <img
src='http://bogdan.org.ua/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F05%2F23%2Fdirectory-based-random-image-rotation-php-script.html&amp;title=Directory-based%20random%20image%20rotation%20PHP%20script" id="wpa2a_40"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/05/23/directory-based-random-image-rotation-php-script.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Executing and checking background shell process from PHP</title><link>http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html</link> <comments>http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html#comments</comments> <pubDate>Wed, 23 May 2007 14:53:33 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Links]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html</guid> <description><![CDATA[Found a nicely illustrated method for running a background shell command from PHP and continuously checking if the process is still running. Here's sample code without explanations: PLAIN TEXT PHP: function run_in_background&#40;$Command, $Priority = 0&#41; &#123; &#160;if&#40;$Priority&#41; &#160; $PID = shell_exec&#40;"nohup nice -n $Priority $Command 2&#62; /dev/null &#38; echo $!"&#41;; &#160;else &#160; $PID = shell_exec&#40;"nohup [...]]]></description> <content:encoded><![CDATA[<p>Found a nicely illustrated method for <a
href="http://nsaunders.wordpress.com/2007/01/12/running-a-background-process-in-php/" rel="nofollow"  target="_blank">running a background shell command from PHP and continuously checking if the process is still running</a>.</p><p>Here's sample code without explanations:</p><div
class="igBar"><span
id="lphp-17"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-17'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-17"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> run_in_background<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$Command</span>, <span
style="color:#0000FF;">$Priority</span> = <span
style="color:#CC66CC;color:#800000;">0</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">if</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$Priority</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#0000FF;">$PID</span> = <a
href="http://www.php.net/shell_exec" rel="nofollow" ><span
style="color:#000066;">shell_exec</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"nohup nice -n $Priority $Command 2&gt; /dev/null &amp; echo $!"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">else</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color:#0000FF;">$PID</span> = <a
href="http://www.php.net/shell_exec" rel="nofollow" ><span
style="color:#000066;">shell_exec</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"nohup $Command 2&gt; /dev/null &amp; echo $!"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">return</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$PID</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> is_process_running<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$PID</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/exec" rel="nofollow" ><span
style="color:#000066;">exec</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"ps $PID"</span>, <span
style="color:#0000FF;">$ProcessState</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">return</span><span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/count" rel="nofollow" ><span
style="color:#000066;">count</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$ProcessState</span><span
style="color:#006600; font-weight:bold;">&#41;</span>&gt;= <span
style="color:#CC66CC;color:#800000;">2</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><blockquote><p>To run something like hmmsearch from the HMMER package, you’d do this:</p></blockquote><div
class="igBar"><span
id="lphp-18"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-18'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-18"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Running hmmsearch. . ."</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$ps</span> = run_in_background<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"hmmsearch $hmmfile $fastafile&gt; $outfile"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#616100;">while</span><span
style="color:#006600; font-weight:bold;">&#40;</span>is_process_running<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$ps</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">" . "</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/ob_flush" rel="nofollow" ><span
style="color:#000066;">ob_flush</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;flush<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<a
href="http://www.php.net/sleep" rel="nofollow" ><span
style="color:#000066;">sleep</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#CC66CC;color:#800000;">1</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F05%2F23%2Fexecuting-and-checking-background-shell-process-from-php.html&amp;title=Executing%20and%20checking%20background%20shell%20process%20from%20PHP" id="wpa2a_44"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/05/23/executing-and-checking-background-shell-process-from-php.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to find absolute path on a web-server (using PHP)</title><link>http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server-using-php.html</link> <comments>http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server-using-php.html#comments</comments> <pubDate>Mon, 30 Apr 2007 11:53:51 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Notepad]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <guid
isPermaLink="false">http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server.html</guid> <description><![CDATA[When using PHP, the simplest way to find the absolute path of your files/folders on the server is by creating a simple path.php file with the following contents (click on the "Plain text" box header for copy-pasting): PLAIN TEXT PHP: &#60;?php echo realpath&#40;dirname&#40;__FILE__&#41;&#41;; ?&#62; Put the new file anywhere in the web-accessible folder on your [...]]]></description> <content:encoded><![CDATA[<p>When using PHP, the simplest way to find the absolute path of your files/folders on the server is by creating a simple path.php file with the following contents (click on the "Plain text" box header for copy-pasting):</p><div
class="igBar"><span
id="lphp-21"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-21'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-21"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">&lt;?php</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <a
href="http://www.php.net/realpath" rel="nofollow" ><span
style="color:#000066;">realpath</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/dirname" rel="nofollow" ><span
style="color:#000066;">dirname</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#000000; font-weight:bold;">__FILE__</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">?&gt;</span></div></li></ol></div></div></div><p></p><p>Put the new file anywhere in the web-accessible folder on your server,<br
/> then just access that file from your favourite web-browser - and you'll have the absolute path shown to you.</p><p>Alternatively, you may use the following code:</p><div
class="igBar"><span
id="lphp-22"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-22'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-22"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">&lt;?php</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a
href="http://www.php.net/echo" rel="nofollow" ><span
style="color:#000066;">echo</span></a> <a
href="http://www.php.net/getcwd" rel="nofollow" ><span
style="color:#000066;">getcwd</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">?&gt;</span></div></li></ol></div></div></div><p> This also should display the absolute path on your server.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server-using-php.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server-using-php.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F04%2F30%2Fhow-to-find-absolute-path-on-a-web-server-using-php.html&amp;title=How%20to%20find%20absolute%20path%20on%20a%20web-server%20%28using%20PHP%29" id="wpa2a_48"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/04/30/how-to-find-absolute-path-on-a-web-server-using-php.html/feed</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>Drupal internationalization (i18n) and localization (l10n)</title><link>http://bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html</link> <comments>http://bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html#comments</comments> <pubDate>Sat, 10 Mar 2007 13:48:32 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[CMS]]></category> <category><![CDATA[Drupal]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[i18n]]></category> <category><![CDATA[l10n]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html</guid> <description><![CDATA[This is a collection of links related to the multiple-language content in Drupal CMS. i18n module i18n: Getting the whole thing to work : http://drupal.org/node/81094 Patch: Translations of menu titles and descriptions: http://drupal.org/node/70919 Translated links: http://drupal.org/node/67814 i18n: menu not expanding with URL-Alias: http://drupal.org/node/80820 There was an alternative module to i18n, but I cannot find it [...]]]></description> <content:encoded><![CDATA[<p>This is a collection of links related to the multiple-language content in Drupal CMS.</p><p><a
href="http://drupal.org/project/i18n" rel="nofollow" >i18n module</a><br
/> i18n: Getting the whole thing to work : <a
href="http://drupal.org/node/81094" rel="nofollow" >http://drupal.org/node/81094</a><br
/> Patch: Translations of menu titles and descriptions: <a
href="http://drupal.org/node/70919" rel="nofollow" >http://drupal.org/node/70919</a><br
/> Translated links: <a
href="http://drupal.org/node/67814" rel="nofollow" >http://drupal.org/node/67814</a><br
/> i18n: menu not expanding with URL-Alias: <a
href="http://drupal.org/node/80820" rel="nofollow" >http://drupal.org/node/80820</a></p><p>There was an alternative module to i18n, but I cannot find it at the moment.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F03%2F10%2Fdrupal-internationalization-i18n-and-localization-l10n.html&amp;title=Drupal%20internationalization%20%28i18n%29%20and%20localization%20%28l10n%29" id="wpa2a_52"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/03/10/drupal-internationalization-i18n-and-localization-l10n.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>dotProject 2.0.4/2.1.2/2.1.3 on shared hosting</title><link>http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html</link> <comments>http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html#comments</comments> <pubDate>Mon, 22 Jan 2007 18:04:28 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Software]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[dotProject]]></category> <category><![CDATA[fix]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[project management]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2007/01/22/dotproject-on-godaddycom-shared-hosting.html</guid> <description><![CDATA[Update: the same solution seems to still apply to dotProject 2.1.2; the post instructions have been modified for dP 2.1.2. Update 2: fsmullin suggested a method to fix a similar error in index_table.php, the files_count_max cannot be found error when you click the FILES tab/menu item. His suggestion is now incorporated into the post. Update [...]]]></description> <content:encoded><![CDATA[<p><ins
datetime="2009-01-17T22:40:24+00:00">Update:</ins> the same solution seems to still apply to dotProject 2.1.2; the post instructions have been modified for dP 2.1.2.</p><p><ins
datetime="2009-01-30T19:21:41+00:00">Update 2:</ins> fsmullin <a
href="http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html#comment-97643">suggested</a> a method to fix a similar error in index_table.php, the <strong>files_count_max cannot be found error</strong> when you click the <strong>FILES</strong> tab/menu item. His suggestion is now incorporated into the post.</p><p><ins
datetime="2010-06-21T12:43:39+00:00">Update 3:</ins> this post is still relevant for dotProject 2.1.3.</p><p>In one of my recent posts about <a
href="http://bogdan.org.ua/2007/01/21/project-management-software.html">project management software</a> I stated the desire to extensively test dotProject 2.0.4. However, many shared hosting providers appear incompatible with dotProject: the right to CREATE TEMPORARY TABLES in MySQL is not granted, but is needed by dotProject.</p><p>Here's sample error (2.0.4):</p><blockquote><p>query failed(CREATE TEMPORARY TABLE tasks_sum SELECT task_project, COUNT(distinct task_id) AS total_tasks,<br
/> SUM(task_duration * task_percent_complete * IF(task_duration_type = 24, 8.0, task_duration_type))/<br
/> SUM(task_duration * IF(task_duration_type = 24, 8.0, task_duration_type)) AS project_percent_complete FROM `tasks` GROUP BY task_project)</p></blockquote><p>For 2.1.2, sample error would be:</p><blockquote><p>Table 'tasks_total' doesn't exist</p></blockquote><p>I tried looking for solutions, and here's what I found...<br
/> <span
id="more-106"></span><br
/> First of all, I tried issuing the "grant" command to try enabling temporary tables:</p><blockquote><p>GRANT CREATE TEMPORARY TABLES ON dot_projects.* to dot_projects@x.myserver.com;</p></blockquote><p>Expectedly, this didn't work: "access denied for user ....".</p><p>Then I tried looking for a ready-to-apply solution. Here are the links relevant to the topic, if you happen to prefer "the source", and not the retelling: <a
href="http://www.dotproject.net/vbulletin/archive/index.php/t-29.html" rel="nofollow" >link 1</a>, <a
href="http://www.dotproject.net/vbulletin/showthread.php?t=2749&#038;highlight=temporary" rel="nofollow" >link 2</a>, <a
href="http://www.dotproject.net/vbulletin/archive/index.php/t-2753.html" rel="nofollow" >link 3</a>, and <a
href="http://www.dotproject.net/vbulletin/showthread.php?t=4261" rel="nofollow" >link 4</a>.</p><p>However, none of the solutions described behind the links worked for me.</p><p><strong>Here's my solution (error fix).</strong></p><p>To fix, instead of creating temporary tables each time they are needed (what is impossible on many shared hostings), we need to create the necessary tables once. Then, instead of dropping temporary tables, we just truncate our "static" tables.</p><p>Here's how we proceed.</p><ol><li>Issue once the following MySQL statements (using, e.g., phpMyAdmin):<div
class="igBar"><span
id="lsql-32"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('sql-32'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">SQL:</span><div
id="sql-32"><div
class="sql"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_problems`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_log_problem`</span> TINYINT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">1</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_critical`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`critical_task`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`project_actual_end_date`</span> DATETIME <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_sum`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`total_tasks`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">6</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`project_percent_complete`</span> VARCHAR<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span>,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`project_duration`</span> VARCHAR<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_summy`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`my_tasks`</span> varchar<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">10</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_users`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span>,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`user_id`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_total`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`task_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">11</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span> ,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`total_tasks`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color: #cc66cc;color:#800000;">6</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`files_count_max`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`file_versions`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #cc66cc;color:#800000;">0</span>,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`file_lastversion`</span> float <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #ff0000;">'0'</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`file_version_id`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #cc66cc;color:#800000;">0</span>,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff0000;">`file_project`</span> INT<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #cc66cc;color:#800000;">0</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li></ol></div></div></div><p> This will create all the necessary tables.<br
/> <em>Note:</em> <strong>tasks_total</strong> and <strong>files_count_max</strong> tables are 2.1.2-specific.<br
/> <em>Another note</em>: for 2.1.2, the <strong>tasks_sum</strong> table is one field shorter:<div
class="igBar"><span
id="lsql-33"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('sql-33'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">SQL:</span><div
id="sql-33"><div
class="sql"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">CREATE</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> <span
style="color: #993333; font-weight: bold;">IF</span> <span
style="color: #993333; font-weight: bold;">NOT</span> <span
style="color: #993333; font-weight: bold;">EXISTS</span> <span
style="color: #ff0000;">`tasks_sum`</span> <span
style="color:#006600; font-weight:bold;">&#40;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color: #ff0000;">`task_project`</span> int<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color: #ff0000;">`project_percent_complete`</span> varchar<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span>,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span
style="color: #ff0000;">`project_duration`</span> varchar<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color: #cc66cc;color:#800000;">11</span><span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color: #993333; font-weight: bold;">DEFAULT</span> <span
style="color: #993333; font-weight: bold;">NULL</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM;</div></li></ol></div></div></div><p></li><li><a
href="http://www.dotproject.net/vbulletin/showthread.php?t=2753" rel="nofollow" >Now</a>, in <strong>classes/query.class.php</strong> at line 393 (for dotProject 2.0.4; just search for the matching line in 2.1.2) <strong>replace</strong> this line:<div
class="igBar"><span
id="lphp-34"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-34'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-34"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span> = <span
style="color:#FF0000;">'CREATE TEMPORARY TABLE '</span> . <span
style="color:#0000FF;">$this</span>-&gt;_table_prefix . <span
style="color:#0000FF;">$this</span>-&gt;<span
style="color:#006600;">create_table</span>;</div></li></ol></div></div></div><p> with these:</p><div
class="igBar"><span
id="lphp-35"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-35'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-35"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">//$q = 'CREATE TEMPORARY TABLE ' . $this-&gt;_table_prefix . $this-&gt;create_table;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span> = <span
style="color:#FF0000;">'INSERT INTO '</span> . <span
style="color:#0000FF;">$this</span>-&gt;_table_prefix . <span
style="color:#0000FF;">$this</span>-&gt;<span
style="color:#006600;">create_table</span>;</div></li></ol></div></div></div><p> Now we won't get any errors about the tables which fail to be created.</li><li>Next, <strong>replace</strong> the following text in <strong>modules/projects/projects.class.php</strong> (lines 388-392 for 2.0.4):<div
class="igBar"><span
id="lphp-36"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-36'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-36"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// Let's delete temporary tables</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span>&nbsp; = <span
style="color:#000000; font-weight:bold;">new</span> DBQuery;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span>-&gt;<span
style="color:#006600;">dropTemp</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">'tasks_sum, tasks_summy, tasks_critical, tasks_problems, tasks_users'</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span>-&gt;<span
style="color:#006600;">exec</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span>-&gt;<span
style="color:#006600;">clear</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p> with this code:</p><div
class="igBar"><span
id="lphp-37"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-37'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-37"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// Let's delete temporary tables</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_sum"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_summy"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_critical"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_problems"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_users"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE tasks_total"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$q</span>&nbsp; = <span
style="color:#000000; font-weight:bold;">new</span> DBQuery;</div></li></ol></div></div></div><p> Note: <strong>$sql = "TRUNCATE TABLE tasks_sum"; db_exec($sql);</strong> line is 2.1.2-specific.<br
/> At this point, you will no longer receive error messages while on the "projects" tab.</li><li><em>(this point applies to 2.1.2 only)</em> <strong>Replace</strong> lines 222 and 223 in <strong>modules/files/index_table.php</strong><div
class="igBar"><span
id="lphp-38"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-38'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-38"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$r</span>-&gt;<span
style="color:#006600;">dropTemp</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">'files_count_max'</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$r</span>-&gt;<span
style="color:#006600;">exec</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p> with:</p><div
class="igBar"><span
id="lphp-39"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-39'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-39"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">//$r-&gt;dropTemp('files_count_max');</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">//$r-&gt;exec();</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$sql</span> = <span
style="color:#FF0000;">"TRUNCATE TABLE files_count_max"</span>; db_exec<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$sql</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p></li><li><strong>Optionally</strong>, if you want to improve the performance of dotProject specifically for these tables, change the 'engine' for the above-mentioned tables to 'memory'. To do that, execute the following SQL statements:<div
class="igBar"><span
id="lsql-40"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('sql-40'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">SQL:</span><div
id="sql-40"><div
class="sql"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_problems engine=memory;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_critical engine=memory;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_sum engine=memory;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_summy engine=memory;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_users engine=memory;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> tasks_total engine=memory;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #993333; font-weight: bold;">ALTER</span> <span
style="color: #993333; font-weight: bold;">TABLE</span> files_count_max engine=memory;</div></li></ol></div></div></div><p> This change will make MySQL keep these tables in RAM. As they are used as temporary tables, this decreases disk I/O a lot while working with dotProject. Of course, YMMV - to apply this change or not depends on where is your bottleneck.</li><p>Comments and further improvements are welcome.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2007%2F01%2F22%2Fdotproject-204-on-godaddy-shared-hosting.html&amp;title=dotProject%202.0.4%2F2.1.2%2F2.1.3%20on%20shared%20hosting" id="wpa2a_56"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2007/01/22/dotproject-204-on-godaddy-shared-hosting.html/feed</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>HTTP caching: universal approach and sample code</title><link>http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html</link> <comments>http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html#comments</comments> <pubDate>Sat, 09 Dec 2006 09:16:53 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[caching]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[http]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html</guid> <description><![CDATA[As described in my previous post, there are some rather simple mechanisms to enable visitor's browser to cache content, and avoid unnecessary load on your servers. In this post I'll take a look at some parts of the practical implementation of the caching mechanism on the server, using PHP. I think of caching as a [...]]]></description> <content:encoded><![CDATA[<p>As described in my <a
href="http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html" title="HTTP caching: request and response headers">previous post</a>, there are some rather simple mechanisms to enable visitor's browser to cache content, and avoid unnecessary load on your servers. In this post I'll take a look at some parts of the practical implementation of the caching mechanism on the server, using PHP.<br
/> <span
id="more-50"></span><br
/> I think of caching as a set of relatively independent procedures:</p><ol><li>Process browser's request - find out, if the browser is asking for content for the first time, or is looking for an updated version. If the browser's content is fresh, just reply that it's fresh. Otherwise, proceed to step 2. Also proceed to step 2, if this is a first-time request.</li><li>If this is a first-time request, check if we have a fresh locally cached content, and send it in response, to bypass <em>de novo</em> contet generation. If local cache is stale, proceed to step 3.</li><li>Generate new (fresh) content cache item, and send it to browser, together with cache-enabling headers.</li></ol><p>I decided to put all the header-related processing into one function, and all the cache-creation and sending - into another. If you prefer, you can make an object with two or more methods, but I see no need in doing so.</p><p>Here's the headers part:</p><div
class="igBar"><span
id="lphp-44"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-44'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-44"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> HTTP_caching<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$timestamp</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#008000;">/*</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * HTTP_caching(v0.3)</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * checks headers for eTag or Modified request,</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * and replies with HTTP 304 Not Modified</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * if $timestamp is equal to the requested time/tag</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * returns TRUE if 304, FALSE otherwise</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp;&nbsp; * produces Last-Modified and ETag headers from $timestamp</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">&nbsp; &nbsp; */</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$latest</span> = <a
href="http://www.php.net/gmdate" rel="nofollow" ><span
style="color:#000066;">gmdate</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">'D, d M Y H:i:s'</span>, <span
style="color:#0000FF;">$timestamp</span><span
style="color:#006600; font-weight:bold;">&#41;</span> . <span
style="color:#FF0000;">' GMT'</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$etag</span> = <a
href="http://www.php.net/md5" rel="nofollow" ><span
style="color:#000066;">md5</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$latest</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$not</span> = <span
style="color:#000000; font-weight:bold;">false</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <a
href="http://www.php.net/isset" rel="nofollow" ><span
style="color:#000066;">isset</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$_SERVER</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'HTTP_IF_MODIFIED_SINCE'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$_SERVER</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'HTTP_IF_MODIFIED_SINCE'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#0000FF;">$latest</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"HTTP/1.1 304 Not Modified"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Status: 304 Not Modified"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$not</span> = <span
style="color:#000000; font-weight:bold;">true</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">elseif</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <a
href="http://www.php.net/isset" rel="nofollow" ><span
style="color:#000066;">isset</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$_SERVER</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'HTTP_IF_NONE_MATCH'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> <span
style="color:#0000FF;">$_SERVER</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'HTTP_IF_NONE_MATCH'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> == <span
style="color:#0000FF;">$etag</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"HTTP/1.1 304 Not Modified"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Status: 304 Not Modified"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#0000FF;">$not</span> = <span
style="color:#000000; font-weight:bold;">true</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>!<span
style="color:#0000FF;">$not</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Last-Modified: "</span> . <span
style="color:#0000FF;">$latest</span> <span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"ETag: "</span> . <span
style="color:#0000FF;">$etag</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#616100;">return</span> <span
style="color:#0000FF;">$not</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><p>This function checks two caching-related request headers: If-None-Match and If-Modified-Since. Use of two headers is redundant, but this was done with an idea to provide different caching methods for different content types in the future. Timestamp-based approach should be sufficient in most cases, but having ETag as well does not hurt.</p><p>The parameter this function takes - $timestamp - is the date of the locally cached content item. We should check if the cached item exists before calling HTTP_caching; and if cached item does not exist, we should create it and then call HTTP_caching with the timestamp of the newly generated cached content item.</p><p>Function is utterly simple, but needs some explaining comments:</p><ul><li>There is a convenient function "apache_request_headers", but as its name implies, it works only under apache. Thus I had to use global PHP variables for fetching specific request headers. However, this approach also doesn't work on all hosting providers - you just do not get those headers, though they are sent by the browser. But you still benefit from local caching, and the only drawback of being unable to process request headers is that you waste traffic sending data which could have been unsent.</li><li>I'm also sending two equal headers - standard HTTP/1.1, and outdated Status header. This is redundant (sending Status might be removed), but depending on how your PHP is installed (as apache-httpd module or CGI) you may want to leave both in place, or experiment and leave the one which actually works.</li></ul><p>Now, let's move on to actual caching. The simplest and quite reliable method of identifying any object within your cache is md5(url) - that is, the hash of the request URL. Note, that you might want to hash not the complete URL (starting with http://), but only the part after the TLD's slash, e.g. for complete URL http://bogdan.org.ua/2006/10/27/xnameorg-down-largest-ddos-they-ever-had.html you would hash only the "xnameorg-down-largest-ddos-they-ever-had.html" part (or "2006/10/27/xnameorg-down-largest-ddos-they-ever-had.html", if the filename part of the path might be non-unique). Evidently, this will save you from generating cache both for "http://www.bogdan.org.ua/2006/10/27/xnameorg-down-largest-ddos-they-ever-had.html" and for "http://bogdan.org.ua/2006/10/27/xnameorg-down-largest-ddos-they-ever-had.html" (differing only in "www." part).</p><p>Here's what we need to do (some evident micro-tunings dropped for clarity):</p><ol><li>Hash the request URL.</li><li>Check if that cache item exists. If yes - go to step 4. If not - step 3.</li><li>Create cache item (cache file), set the file name to the hash of the request URL, and store the file in your cache directory (e.g. '/cache').</li><li>Read cache file modification timestamp.</li><li>Call HTTP_caching with that timestamp. If it returns true - do nothing. Else - continue to step 6.</li><li>Read cache file and send it to browser.</li></ol><p>To make this part of caching system wrapped in a single universally applicable function, you will need to define some "content-generating" handler function, which will be called when local cache file must be regenerated. "Content-generation" might be as simple as just reading some file from the disk; or you could wrap your index.php file in cache-checking block, so that page call and generation occur only if there is no readily available cached page.</p><div
class="igBar"><span
id="lphp-45"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-45'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-45"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> caching<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$handler_function</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#FF9933; font-style:italic;">// first, check if we have existing cache</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#FF9933; font-style:italic;">// of currently requested resource in the 'cache' directory</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#0000FF;">$cachedfile</span> = <span
style="color:#FF0000;">'cache/'</span> . <a
href="http://www.php.net/md5" rel="nofollow" ><span
style="color:#000066;">md5</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$_SERVER</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'REQUEST_URI'</span><span
style="color:#006600; font-weight:bold;">&#93;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><a
href="http://www.php.net/file_exists" rel="nofollow" ><span
style="color:#000066;">file_exists</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <a
href="http://www.php.net/is_file" rel="nofollow" ><span
style="color:#000066;">is_file</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#006600; font-weight:bold;">&#123;</span> <span
style="color:#FF9933; font-style:italic;">// cache exists. now check if it is up-to-date</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#0000FF;">$filetime</span> = <a
href="http://www.php.net/filemtime" rel="nofollow" ><span
style="color:#000066;">filemtime</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#0000FF;">$modif</span> = <a
href="http://www.php.net/time" rel="nofollow" ><span
style="color:#000066;">time</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span> - <span
style="color:#0000FF;">$filetime</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// CACHE_PERIOD is a constant defined somewhere else,</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// e.g. define('CACHE_PERIOD',300)</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$modif</span> &lt;= <span
style="color:#006600; font-weight:bold;">&#40;</span>int<span
style="color:#006600; font-weight:bold;">&#41;</span>CACHE_PERIOD<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <span
style="color:#616100;">if</span> <span
style="color:#006600; font-weight:bold;">&#40;</span> HTTP_caching<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$filetime</span><span
style="color:#006600; font-weight:bold;">&#41;</span> === <span
style="color:#000000; font-weight:bold;">false</span> <span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#123;</span> <span
style="color:#FF9933; font-style:italic;">// we need to send cached content to browser - no</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// if-modified-since or if-none-match request headers</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; <span
style="color:#0000FF;">$expires</span> = <a
href="http://www.php.net/gmdate" rel="nofollow" ><span
style="color:#000066;">gmdate</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">'D, d M Y H:i:s'</span>, <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$filetime</span> + CACHE_PERIOD<span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> . <span
style="color:#FF0000;">' GMT'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;&nbsp; send_cached_file<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span>, CACHE_PERIOD, <span
style="color:#0000FF;">$expires</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// if HTTP_caching returned 'true' - we are done with '304' header.</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// finally, ensure nothing else happens after sending contents...</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp; <a
href="http://www.php.net/exit" rel="nofollow" ><span
style="color:#000066;">exit</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// if cache is old - just call $handler_function,</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#FF9933; font-style:italic;">// assuming that it returns all the content</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&nbsp; &nbsp;<span
style="color:#0000FF;">$new_cache</span> = <span
style="color:#0000FF;">$handler_function</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// if instead of using $handler_function you wrap some code:</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// ob_start();</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// include &quot;page_generation.php&quot;;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// $new_cache = ob_get_contents();</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// ob_end_clean();</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$fp</span> = <a
href="http://www.php.net/fopen" rel="nofollow" ><span
style="color:#000066;">fopen</span></a> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span>, <span
style="color:#FF0000;">"w"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/fwrite" rel="nofollow" ><span
style="color:#000066;">fwrite</span></a> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$fp</span>, <span
style="color:#0000FF;">$new_cache</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/fclose" rel="nofollow" ><span
style="color:#000066;">fclose</span></a> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$fp</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$filetime</span> = <a
href="http://www.php.net/filemtime" rel="nofollow" ><span
style="color:#000066;">filemtime</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#0000FF;">$expires</span> = <a
href="http://www.php.net/gmdate" rel="nofollow" ><span
style="color:#000066;">gmdate</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">'D, d M Y H:i:s'</span>, <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$filetime</span> + CACHE_PERIOD<span
style="color:#006600; font-weight:bold;">&#41;</span> <span
style="color:#006600; font-weight:bold;">&#41;</span> . <span
style="color:#FF0000;">' GMT'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; send_cached_file<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span>, CACHE_PERIOD, <span
style="color:#0000FF;">$expires</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span
style="color:#006600; font-weight:bold;">&#125;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><p>Below is a function which sends cached files to the browser. Note, that it lacks content-type parameter (or content-type detection code).</p><div
class="igBar"><span
id="lphp-46"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-46'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-46"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#000000; font-weight:bold;">function</span> send_cached_file<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span>, <span
style="color:#0000FF;">$cache</span>, <span
style="color:#0000FF;">$expires</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#123;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// I omitted Content-Length and Content-Type for simplicity,</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// though it's better to send them</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"HTTP/1.1 200 OK"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Status: 200 OK"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Pragma: cache"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Cache-Control: max-age="</span>.<span
style="color:#0000FF;">$cache</span>.<span
style="color:#FF0000;">", min-fresh="</span>.<span
style="color:#0000FF;">$cache</span>.<span
style="color:#FF0000;">", no-transform"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color:#FF9933; font-style:italic;">// Content-Type needs adjustment on a per-content-item basis</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Content-Type: text/html"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Content-Length: "</span> . <a
href="http://www.php.net/filesize" rel="nofollow" ><span
style="color:#000066;">filesize</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/header" rel="nofollow" ><span
style="color:#000066;">header</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#FF0000;">"Expires: $expires"</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a
href="http://www.php.net/readfile" rel="nofollow" ><span
style="color:#000066;">readfile</span></a><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$cachedfile</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#125;</span></div></li></ol></div></div></div><p></p><p>(Note: function 'caching' was not tested; if you find any errors, or if it just doesn't work for you - let me know via the <a
href="http://bogdan.org.ua/contact">contact form</a>, I'll try to fix my error.)</p><p>For the explanation of what headers mean, refer to <a
href="http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html" title="HTTP caching: request and response headers">my previous post</a>.</p><p>This is it for now. Coming next might be some useful information on differences in HTTP headers handling between PHP installed as a module and PHP as CGI.</p><p>As always, comments/suggestions are welcome.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F12%2F09%2Fhttp-caching-universal-approach-and-sample-code.html&amp;title=HTTP%20caching%3A%20universal%20approach%20and%20sample%20code" id="wpa2a_60"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/12/09/http-caching-universal-approach-and-sample-code.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>HTTP caching: request and response headers</title><link>http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html</link> <comments>http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html#comments</comments> <pubDate>Wed, 18 Oct 2006 15:22:25 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html</guid> <description><![CDATA[In this post: some caching-related HTTP request and response headers discussed. Modern websites are "dynamic" by nature - content you get depends on a number of variables and conditions. The simplest example - being a "guest" or a "registered" user of some forum; in both cases you get content generated by the same script/program, but [...]]]></description> <content:encoded><![CDATA[<p><em>In this post: some caching-related HTTP request and response headers discussed.</em></p><p>Modern websites are "dynamic" by nature - content you get depends on a number of variables and conditions. The simplest example - being a "guest" or a "registered" user of some forum; in both cases you get content generated by the same script/program, but it differs because of your "registered" state.</p><p>Another example - web-photogallery. By design, it is wise to always keep the original photo (the largest and presumably of the highest quality). When gallery visitor's browser requests any smaller version of the photo - we can dynamically resize (often downsize) the original and feed the resulting photo to the browser. This scheme works OK until your gallery gets more and more visitors - CPU load climbs up and increases wait time when accessing your gallery. Evidently, caching is needed.<br
/> <span
id="more-48"></span><br
/> Caching is a process of storing some integral (independent, atomic) piece of data in order to quickly retrieve it later, when asked for, in cases, when creating/accessing that piece of data without storing would require more time. Caching provides means to bypass calculation-intensive steps of content creation, and thus decreases server load, and allows your server to generate content faster, and deliver it to more visitors.</p><p>Probably the most important parameter of caching is "cache period" - time, during which cached piece of data is considered "fresh" and is read of the cache; if the cached piece of data exists more than "cache period" - it is considered "stale", and should be replaced with newly recreated piece of data.</p><p>When web-server sends some content to the browser, there are three main "RFC-compliant" headers it may use to instruct the browser how to cache that content. These headers are Last-Modified, ETag, and Cache-Control. Two of these - Last-Modified and ETag - force the compliant browser to generate specific request tags: If-Modified-Since and If-None-Match. The Cache-Control header instructs the browser's cache on how to handle data. For complete technical description, please refer to <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow" >RFC2616</a>.</p><p><strong>Last-Modified</strong> informs the browser about the date when the document (or image) was last updated (modified). Correct Last-Modified header must be issued using GMT time, and might look like this example:</p><div
class="igBar"><span
id="lcode-51"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('code-51'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-51"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Last-Modified: Wed, <span
style="color:#800000;color:#800000;">10</span> May <span
style="color:#800000;color:#800000;">2006</span> <span
style="color:#800000;color:#800000;">08</span>:<span
style="color:#800000;color:#800000;">24</span>:<span
style="color:#800000;color:#800000;">39</span> GMT</div></li></ol></div></div></div><p> Sending this response header makes the browser to add corresponding <strong>If-Modified-Since</strong> request header next time it needs to load the resource. Following our example, browser's request would include:</p><div
class="igBar"><span
id="lcode-52"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('code-52'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-52"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">If-Modified-Since: Wed, <span
style="color:#800000;color:#800000;">10</span> May <span
style="color:#800000;color:#800000;">2006</span> <span
style="color:#800000;color:#800000;">08</span>:<span
style="color:#800000;color:#800000;">24</span>:<span
style="color:#800000;color:#800000;">39</span> GMT</div></li></ol></div></div></div><p> Note: browsers are recommended to send back time exactly as it was sent by the server, without modifications. At the moment, I do not know whether and which browsers follow this recommendation. In any case, if you do send time as GMT, you are more likely to get the desired caching effect, than if you send any unique string in the Last-Modified header.</p><p>If a web-server receives If-Modified-Since header, it might reply either with a <em>HTTP/1.1 200 OK</em> (followed by resource data) or <em>HTTP/1.1 304 Not Modified</em> (header itself, no data following). Server response depends on the "fresh" or "stale" status of the resource, as described above.</p><p>Time is not always a good measure of resource "freshness", especially in the case of dynamic sites, which send and process headers themselves, "bypassing" server behaviours. In order to identify some resource, an <strong>ETag</strong> response header can be used:</p><div
class="igBar"><span
id="lcode-53"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('code-53'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-53"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ETag: <span
style="color:#CC0000;">"some-double-quoted-string"</span></div></li></ol></div></div></div><p> ETag is used as a unique resource identifier, which is expected to change if the resource changes. (Here, cyclic redundancy checks come to memory - and that is correct, hashing algorithms like CRC32 and md5 can be used on resource content to generate it's ETag.) When a browser receives ETag header, then on next request it should send "If-None-Match" header:</p><div
class="igBar"><span
id="lcode-54"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('code-54'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-54"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">If-None-Match: <span
style="color:#CC0000;">"some-double-quoted-string"</span></div></li></ol></div></div></div><p> Obviously, string sent by the browser must be equal to one received from the server. Server behaviour in this case is determined by the equality or non-equality of local (server) and received (from browser in If-None-Match) tags: equality hints sending the 304 Not Modified header only, non-equality requires sending 200 OK with content following.</p><p>ETag header value also has weak/strong modifiers, and If-None-Match request header is not the only one for handling ETag, but I will not cover those topics here. Please refer to <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow" >RFC2616</a> for more.</p><p>Finally, <strong>Cache-Control</strong> response header is used to tell the browser how to cache (and if to cache at all) the resource being sent. Cache-Control has a number of possible values (comma-separated if there are more than one), but I will review only some of the values.<br
/> no-cache: forces resource re-validation on each request.<br
/> no-store: (applies to both request and response) forces the resource not to be stored at all; this is usually important for sensitive data.<br
/> max-age: (in seconds) informs about the time period when resource stays "fresh".<br
/> must-revalidate: as the name implies, effect is similar to no-cache.<br
/> no-transform: forbids any resource transformations by proxies/servers in the chain to the end user (don't think it's still relevant, though).</p><p>That is it. Next post will continue the caching topic with the discussion of the universal approach to caching for web-sites.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F10%2F18%2Fhttp-caching-request-and-response-headers.html&amp;title=HTTP%20caching%3A%20request%20and%20response%20headers" id="wpa2a_64"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/10/18/http-caching-request-and-response-headers.html/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>PHP-Nuke 6.0/6.5 to Drupal 4.7.x/5.x migration (conversion)</title><link>http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html</link> <comments>http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html#comments</comments> <pubDate>Fri, 08 Sep 2006 15:29:56 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[CMS]]></category> <category><![CDATA[Drupal]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Web]]></category> <category><![CDATA[conversion]]></category> <category><![CDATA[drupal]]></category> <category><![CDATA[import]]></category> <category><![CDATA[migration]]></category> <category><![CDATA[module]]></category> <category><![CDATA[php-nuke]]></category> <category><![CDATA[phpnuke]]></category> <category><![CDATA[utf8]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/09/08/php-nuke-60-to-drupal-473-migration-conversion.html</guid> <description><![CDATA[Post last updated: April 18, 2010. Now there is a Drupal 6.x module available. It is in no way related to the migrate script(s) below. The newest script version migrates from PHP-Nuke 6.5 to Drupal 5.x. Download the latest version of the migration script. In 2002 I set up a PHPNuke-6.0 - based portal. Eventually [...]]]></description> <content:encoded><![CDATA[<p><em>Post last updated: April 18, 2010.</em></p><p><ins
datetime="2010-04-18T17:54:34+00:00">Now</ins> there is a <a
href="http://drupal.org/project/phpnuke2drupal" rel="nofollow" >Drupal 6.x module available</a>. It is in no way related to the migrate script(s) below.</p><p><ins
datetime="2008-02-19T03:34:21+00:00" title="Note: other version combinations might work as well with no or little modifications. It is known (via bxtra.net) that the script also works for PHPNuke 7.8 to Drupal 5.7 migration - though it isn't known if any modifications were necessary.">The newest script version migrates from PHP-Nuke 6.5 to Drupal 5.x</ins>.<br
/> <a
href="#latest" rel="nofollow" >Download the latest version of the migration script</a>.</p><p>In 2002 I set up a PHPNuke-6.0 - based portal. Eventually it died due to the lack of time investments and support from collaborators. Now, when time came to revive the project, I made a search and decided to use Drupal as a base CMS for the portal.<br
/> In order to migrate userbase from an old portal to the new Drupal-powered one, and following the <a
href="http://drupal.org/node/498" rel="nofollow"  title="Migrating from PHPNuke">topic</a> at drupal.org, I found a <a
href="http://quillem.com/nuke2drupal" rel="nofollow"  title="original nuke_7.0 to drupal_4.6 script">script</a> and its modification.<br
/> I used it to migrate only users, and made some cosmetic changes:</p><ul><li>added options for custom phpnuke table prefixes</li><li>default user name is now = uname (login), not 'temp_name', as before</li><li>I replaced hard-coded links to 'migrate.php' with links to $_SERVER['PHP_SELF'], so that if you rename the script you don't have any problems with that <img
src='http://bogdan.org.ua/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></li><li>now forum topics should not be promoted to the main page (changed 1 to 0 as hinted by Alexis)</li></ul><p>Finally, I would like to thank both <a
href="http://quillem.com/" rel="nofollow" >Karthik Kumar</a> for the original script and Alexis Bellido for the 6.0_to_4.7 modification.<br
/> <span
id="more-24"></span></p><p><ins
datetime="2007-02-25T08:46:18+00:00">Update:</ins> Waldo updated the migration script.<br
/> Here are the changes:</p><ul><li>imports from (a security-patched) Nuke 6.5 -> Drupal 5.1</li><li>imports story categories into Drupal taxonomy</li><li>incorporates phpnuke "Contributor writes..." into story</li><li>incorporates phpnuke admin story "note"</li><li>imports polls (does not import record of who already voted.  You can easily "close" old phpnuke polls via Admin page.  I left them open.)</li><li>imports poll comments</li><li>imports *anonymous* comments for stories, fora, &#038; polls</li><li>imports anonymous forum posts</li><li>filters BBCode to make semi-compatible with Drupal BBCode module</li><li>uses Drupal 5.0 API, and must be run from drupal root directory (/drupal-5/, for example)</li></ul><p>Thanks to Waldo for his work!</p><p><ins
datetime="2007-08-19T15:55:21+00:00"><strong>Latest update:</strong></ins> Waldo sent the newest, improved version of the PHP-Nuke-2-Drupal conversion script. Here is Waldo's description:</p><blockquote><p> New Fixes:</p><ul><li>retain original user registration date &#038; last visit   4/22/07</li><li>fixed user migration bug which could result in screwed max_uid in session table   4/22/07</li><li>store anonymous forum posts names in the log for future compatibility w/Drupal 6   7/16/07</li><li>uses the "tidy" extension (if installed) in php 5.x to clean up the HTML of postings &#038; stories  7/30/07</li><li>bug fixes (possibly) related to drupal 5.2 where the fora had the wrong "changed" date resulting in misordered node lists. 7/30/07</li><li>polls properly remember date of last comment 7/30/07</li></ul><p>If you have the "tidy" PHP extension, it should close all open HTML tags and stuff in stories.</p></blockquote><p><ins
datetime="2008-02-19T15:23:55+00:00">update:</ins> I added to the script some more debug messages in case something goes wrong (as <a
href="http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html#comment-39615">recommended by me</a>) - that pushed the version up to 0.03.</p><p>Also, now MySQL connection collation is set to utf8 before doing anything - this <em>should</em> fix the problems with non-English characters in the imported texts (especially accented/umlauted/etc characters). Thus I upped the version to 0.04. For reference and in case 0.04 doesn't work for you, I keep the older versions as well.</p><p><a
name="latest"> </a><br
/> Download the <a
href="http://bogdan.org.ua/wp-content/uploads/2008/02/phpnuke2drupal-5.x-0.04-w.zip" title="PHP-Nuke 6.0/6.5 to Drupal 4.7.x/5.x migration (conversion)">latest phpnuke2drupal-5.x-0.04-W.zip</a> or the <a
href="http://bogdan.org.ua/wp-content/uploads/2008/02/phpnuke2drupal-5.x-0.04-w.tar.gz" title="PHP-Nuke 6.0/6.5 to Drupal 4.7.x/5.x migration (conversion)">latest tar-gzipped version of the phpnuke2drupal migration script</a>.</p><p><ins
datetime="2010-01-03T21:35:38+00:00">update:</ins> to import Reviews and WebLinks from PHPNuke to Drupal, have a look at <a
href="http://drupal.org/node/202528#comment-724422" rel="nofollow" >this</a> and <a
href="http://drupal.org/node/202528#comment-689245" rel="nofollow" >this</a> comments; you will need CCK, and might need CCK Link Field to import reviews/weblinks.</p><p><u>Previous (older) versions</u>:<br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2008/01/phpnuke2drupal-5.x-0.03-W.zip">phpnuke2drupal-5.x-0.03-W.zip</a><br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2008/01/phpnuke2drupal-5.x-0.03-W.tar.gz">phpnuke2drupal-5.x-0.03-W.tar.gz</a><br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2007/08/phpnuke2drupal-5.x-0.02-w.zip">phpnuke2drupal-5.x-0.02-w.zip</a><br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2007/08/phpnuke2drupal-5.x-0.02-w.tar.gz">phpnuke2drupal-5.x-0.02-w.tar.gz</a><br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2007/02/phpnuke2drupal-5.x-0.01-W.rar">phpnuke2drupal-5.x-0.01 (VValdo's huge improvements first appear here)</a><br
/> <a
href="http://bogdan.org.ua/wp-content/uploads/2006/09/migrate_phpnuke_60_to_drupal_47.txt" title="download">first version with my minor modifications</a></p><p><strong>IMPORTANT:</strong> for migration to work you will need MySQL version to be >= 4.1.1. Earlier versions do not support the STR_TO_DATE() function, used in the migration script.</p><p><strong>IMPORTANT:</strong> if you want to migrate forum entries from PHPNuke to Drupal, be sure to setup forum in your Drupal installation first - otherwise migration of forum entries will fail. See comments 13-17 below for user experiences.</p><p>If you do not get any help here, there is also a drupal.org <a
href="http://drupal.org/node/498" rel="nofollow"  title="Migrating from PHPNuke">migration thread</a>. I will keep this page updated for as long as I get new information about the migration script.</p><p>If you encounter any problems during migration - just search/scan the comments, your problem might have been already solved by someone else.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F09%2F08%2Fphp-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html&amp;title=PHP-Nuke%206.0%2F6.5%20to%20Drupal%204.7.x%2F5.x%20migration%20%28conversion%29" id="wpa2a_68"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/09/08/php-nuke-6-06-5-to-drupal-4-7-x5-x-migration-conversion.html/feed</wfw:commentRss> <slash:comments>74</slash:comments> </item> <item><title>Allow posting duplicate form-name entries with different values</title><link>http://bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html</link> <comments>http://bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html#comments</comments> <pubDate>Wed, 06 Sep 2006 09:04:41 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Bioinformatics]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Science]]></category> <category><![CDATA[http]]></category> <category><![CDATA[HTTP_Client]]></category> <category><![CDATA[HTTP_Request]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html</guid> <description><![CDATA[Sometimes, writing automatic HTML forms processors, you need to post several values with the same name of the form field, e.g.: collection_gene = str_chrom_name collection_gene = gene_stable_id This is against the RFC on form fields design and submitting, but this approach is used - for example, by Ensembl. I spent some time to figure out [...]]]></description> <content:encoded><![CDATA[<p>Sometimes, writing automatic HTML forms processors, you need to post several values with the same name of the form field, e.g.:<br
/> collection_gene = str_chrom_name<br
/> collection_gene = gene_stable_id</p><p>This is against the RFC on form fields design and submitting, but this approach is used - for example, by <a
href="http://www.ensembl.org/index.html" rel="nofollow"  title="Ensembl genome automatic annotation database" target="_blank">Ensembl</a>. I spent some time to figure out how to make HTTP_Client and HTTP_Request submit multiple 'name-value' pairs instead of one (the latest defined, which overrides the previous). The solution is extremely simple:<br
/> <span
id="more-23"></span></p><div
class="igBar"><span
id="lphp-56"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-56'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-56"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">/*</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;"> allow posting duplicate form-name</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;"> entries with different values</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#008000;">*/</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$params</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'useBrackets'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#000000; font-weight:bold;">false</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$req</span> = <span
style="color:#000000; font-weight:bold;">&amp;new</span> HTTP_Client<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$params</span>, <span
style="color:#0000FF;">$headers</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p></p><p>After setting 'useBrackets' parameter to 'false', HTTP_Client/HTTP_Request do post multiple lines as you would want it.</p><p>Hope this saves you some time.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F09%2F06%2Fallow-posting-duplicate-form-name-entries-with-different-values.html&amp;title=Allow%20posting%20duplicate%20form-name%20entries%20with%20different%20values" id="wpa2a_72"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/09/06/allow-posting-duplicate-form-name-entries-with-different-values.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Avoiding out of memory fatal error when using HTTP_Client or HTTP_Request</title><link>http://bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html</link> <comments>http://bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html#comments</comments> <pubDate>Wed, 06 Sep 2006 08:58:29 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[Bioinformatics]]></category> <category><![CDATA[how-to]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[Science]]></category> <category><![CDATA[http]]></category> <category><![CDATA[HTTP_Client]]></category> <category><![CDATA[HTTP_Request]]></category> <category><![CDATA[memory]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html</guid> <description><![CDATA[If you fetch large amounts of data (e.g. over 2MB per request) using HTTP_Client (or HTTP_request), you may get "out of memory" fatal errors, especially if: memory_limit is set to default 8M, and you process multiple pages using single non-reset instance of HTTP_Client object. This problem can manifest itself by producing fatal error after a [...]]]></description> <content:encoded><![CDATA[<p>If you fetch large amounts of data (e.g. over 2MB per request) using HTTP_Client (or HTTP_request), you may get "out of memory" fatal errors, especially if:</p><ol><li>memory_limit is set to default 8M, and</li><li>you process multiple pages using single non-reset instance of HTTP_Client object.</li></ol><p>This problem can manifest itself by producing fatal error after a couple of cycles of successful page retrieval - but always, if run with the same parameters, after some constant or only slightly variable number of cycles.</p><p>In my case the problem was that HTTP_Request (a dependancy of HTTP_Client) was holding in memory all the previously fetched pages of the current session (the 'history' feature). To force HTTP_Request to hold only the most recent page, you need to 'disable' history after creating the HTTP_Client or HTTP_Request object instance:</p><div
class="igBar"><span
id="lphp-58"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-58'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-58"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$req</span> = <span
style="color:#000000; font-weight:bold;">&amp;new</span> HTTP_Client<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$params</span>, <span
style="color:#0000FF;">$headers</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// disable history to save memory</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$req</span>-&gt;<span
style="color:#006600;">enableHistory</span><span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#000000; font-weight:bold;">false</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p></p><p>Hope this helps you.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F09%2F06%2Favoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html&amp;title=Avoiding%20out%20of%20memory%20fatal%20error%20when%20using%20HTTP_Client%20or%20HTTP_Request" id="wpa2a_76"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/09/06/avoiding-out-of-memory-fatal-error-when-using-http_client-or-http_request.html/feed</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Using PEAR HTTP_Client or HTTP_Request with HTTP proxy</title><link>http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html</link> <comments>http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html#comments</comments> <pubDate>Wed, 06 Sep 2006 08:00:46 +0000</pubDate> <dc:creator>Bogdan</dc:creator> <category><![CDATA[how-to]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programming]]></category> <category><![CDATA[http]]></category> <category><![CDATA[HTTP_Client]]></category> <category><![CDATA[HTTP_Request]]></category> <category><![CDATA[PEAR]]></category> <category><![CDATA[proxy]]></category> <guid
isPermaLink="false">http://www.bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy.html</guid> <description><![CDATA[If you happen to write PHP script, which uses either HTTP_Client or its dependancy HTTP_Request from PEAR, and the script is supposed to work through the HTTP proxy - here are the sample settings you need: PLAIN TEXT PHP: $params&#91;'proxy_user'&#93; = 'proxy_username'; $params&#91;'proxy_pass'&#93; = 'proxy_password'; $params&#91;'proxy_host'&#93; = 'proxy_hostname_or_ip'; $params&#91;'proxy_port'&#93; = 8080; // 3128, ... &#160; [...]]]></description> <content:encoded><![CDATA[<p>If you happen to write PHP script, which uses either HTTP_Client or its dependancy HTTP_Request from PEAR, and the script is supposed to work through the HTTP proxy - here are the sample settings you need:</p><div
class="igBar"><span
id="lphp-60"><a
href="#" rel="nofollow"  onclick="javascript:showPlainTxt('php-60'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PHP:</span><div
id="php-60"><div
class="php"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$params</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'proxy_user'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#FF0000;">'proxy_username'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$params</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'proxy_pass'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#FF0000;">'proxy_password'</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$params</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'proxy_host'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#FF0000;">'proxy_hostname_or_ip'</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$params</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#FF0000;">'proxy_port'</span><span
style="color:#006600; font-weight:bold;">&#93;</span> = <span
style="color:#CC66CC;color:#800000;">8080</span>; <span
style="color:#FF9933; font-style:italic;">// 3128, ...</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#FF9933; font-style:italic;">// I assume $headers were set somewhere else</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#0000FF;">$req</span> = <span
style="color:#000000; font-weight:bold;">&amp;new</span> HTTP_Client<span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#0000FF;">$params</span>, <span
style="color:#0000FF;">$headers</span><span
style="color:#006600; font-weight:bold;">&#41;</span>;</div></li></ol></div></div></div><p></p><p>If your proxy does not need authorization - just drop the proxy_user and proxy_pass parameters.</p><p><a
class="a2a_button_google_plusone addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html"></a><a
class="a2a_button_facebook_like addtoany_special_service" data-href="http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html"></a><a
class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fbogdan.org.ua%2F2006%2F09%2F06%2Fusing-pear-http_client-or-http_request-with-http-proxy-example.html&amp;title=Using%20PEAR%20HTTP_Client%20or%20HTTP_Request%20with%20HTTP%20proxy" id="wpa2a_80"><img
src="http://bogdan.org.ua/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share"/></a></p>]]></content:encoded> <wfw:commentRss>http://bogdan.org.ua/2006/09/06/using-pear-http_client-or-http_request-with-http-proxy-example.html/feed</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
