Categories
PHP

Distributing PHP-GTK Applications on Windows

I am one of those few people who want to do everything with a single tool/utility. I have been curious enough to learn bits of every language but I am even more reluctant to memorize curves of every language. From the day I started programming, I have been looking for a single language to do everything. My quest has not completed. I know it will never be possible to find a “all-in-one” language. So, I minimized my requirements. I want to be able to develop web sites, write shell scripts and develop desktop GUI applications. With php-gtk, the last of the problems gets solved and I have chosen php to be my core language.

php-gtk is a php extension that uses the GTK (GIMP Tool Kit) to let developers build cool GUI apps which run on Linux, Windows, MacOS, BeOS and other platforms. I am currently studying the curves of building GUI software with php-gtk. It was going on fine. But the first problem I faced while distributing my php-gtk apps is that I need to port php, gtk and some other dependencies on the target machine. That hurts. So, I was searching on the internet if I can find a good solution to this problem. Luckily, I found one.

The following ZIP package contains a tool kit for deploying php-gtk apps on windows. Download and unzip the package. Then modify and compile the NSIS script that comes in with the package to build a installation package for your own app.

Download Link:
http://www.dreadsoft.org/php-gtk/pgsk.zip

This package requires the NSIS utility from Nullsoft. Get it from the following address:

Download Link:
http://nsis.sourceforge.net

You must first install NSIS to build the setup files.

Categories
PHP

How Popular Apache and PHP are?

I have been using Apache and PHP together with mySQL for a long time. I just came across the following resources and got a brief idea about how popular they might be among other developers.

PHP:
php is one of the most popular interpreted programming languages of today. PHP was created as a Personal Home Page (php) tool by Rasmus for maintaining his personal web site. But the ease and flexibility of the language has won the hearts of millions. Now php is perhaps the most widely used language for web scripting.

Visit this link: http://www.php.net/usage.php to see a graph illustrating the popularity of php. The graph shows the continual increment in the usage of php over the years.

Apache:
The most popular web server of the present day. The following link shows you a graph from the web server survey conducted by netcraft in March, 2009.

Link: http://news.netcraft.com/archives/2009/03/15/march_2009_web_server_survey.html

From the report, it is seen that 66.65% web servers run on Apache.

 

From the stats it is clear that Apache being free and open sourced, holds the largest share in the web server market. Though the php related chart doesn’t show relative comparison of php with other languages, I wonder if any other languages are used as widely as php is.

Categories
PHP

Duplicating WordPress Blog: “The Hasin Vai” Method

Hasin Hayder, a ZCE and Open Source enthusiast shared a nice trick to duplicate your wordpress blog just using the simple combination of php and mod_rewrite of apache. Read his original blog post here. I am going to explain the mechanism step by step here.

The PHP Code:
Put this code inside the index.php on the target URL’s root directory.

<?php
$dataurl = $primaryurl = ?http://hasin.wordpress.com?;//old domain
$secondaryurl = ?http://blog.ofhas.in?; //new domain
$path =array_keys($_GET);
if(!empty($path[0])) $dataurl = ?{$primaryurl}/{$path[0]}?;
$data = file_get_contents($dataurl);
$pattern = ?~{$primaryurl}/([dS/]+)~?;
$data = preg_replace($pattern,?{$secondaryurl}/$1?,$data);
$data = str_replace(array(?<a href=?{$primaryurl}?,?<form action=?{$secondaryurl}?),array(?<a href=?{$secondaryurl}?,?<form action=?{$primaryurl}?),$data);
echo $data;
?>

The URL REWRITING:
Put the following code inside a .htaccess file or in your apache httpd conf file.

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} (.+)

RewriteRule ^(.*)$ index.php?$1&%{QUERY_STRING}
RewriteCond $1 !^(index.php|images|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

Explanation:
······# The URL Rewriting portion processes the requests to index.php (with and without GET query strings) and other static directories and files (images dir and robots.txt)
······# index.php handles the incoming requests as redirected by the URL Rewriting mechanism.
······# First we define the two data source or URL.

<?php
$dataurl = $primaryurl = ?http://hasin.wordpress.com?;//old domain
$secondaryurl = ?http://blog.ofhas.in?; //new domain
These two lines define the URLs involved. The primary URL is the URL where your wordpress blog is really hosted. The secondary url is the URL of the new location where the blog will show up

······# We sort out the path to the data to display and then copy the data as string.

$path =array_keys($_GET);
if(!empty($path[0])) $dataurl = ?{$primaryurl}/{$path[0]}?;
$data = file_get_contents($dataurl);

······# We then use Regular Expression to change all referrences to our primary URL so that they point to our new location.

$pattern = ?~{$primaryurl}/([dS/]+)~?;
$data = preg_replace($pattern,?{$secondaryurl}/$1?,$data);
$data = str_replace(array(?<a href=?{$primaryurl}?,?<form action=?{$secondaryurl}?),array(?<a href=?{$secondaryurl}?,?<form action=?{$primaryurl}?),$data);
Here we change the URLs and Form Targets. But what about Images with relative URL? I think there’s something wrong with that. I will ask Hasin Vai.

······# Lets print out the modofied data. Close the php block.

echo $data;
?>

That’s all. Put the php code in index.php and the Rewriting Rules in a .htaccess. Place the files in your public_html directory to fire off the ground.

PS: I haven’t yet tested the codes myself. But I believe it would work except for relative image URL.