Jun 23

Why are people still using PHP4 again?

Oh yes, the compatibility issue. Ok, since i’m rewriting all my web apps using Zend Framework now, i guess I don’t have much choice except to switch my PHP installed on my server to PHP5 (Zend Framework was written in PHP5).

Why would i use Zend Framework? two words: beautiful and simple. ZF knows very well how to use the power which comes with PHP5. OOP and design pattern are well written all over the place. Having a quick look at Zend_Controller will explain why i say this.

About the simplicity, Aaron Warmus put it well when he said this,

When evaluating the code within Zend Framework, it was clear that the concept of “Extreme Simplicty” meant that when faced with design decisions, Zend Framework always went with using the power which is built into PHP5 …

In a couple words, extreme simplicity means not reimplementing functionality already available in PHP5.

ZF now in days away from its stable version (currently in 1.0.0-RC2). As many other people out there, i hope ZF will be the rescuer of PHP5 slow adoption. In broad, i hope it will make alot easier for us to build a profesional yet reliable web apps using PHP.

Anyway, i’m switching my server now, wish me luck.

Jun 15

After being delayed for couple days, due to some problem with Pearson Vue database, i finally took my Zend PHP Certification exam last tuesday.

What? are you kidding me, off course i passed the exam. ;-)

So now i’m officially Zend certified engineer.

zce logo

Thanks to Brainmatics for such a good effort preparing my test.

Now, there are three Zend certified engineers from Indonesia. Rock on, dude!

Jun 08

Couple days ago, i was asked by a friend to make a small currency exchange script in PHP. With slow internet connection and so short amount of time, the best thing i could think of was grabbing the number from available currency rate site like this. With curl and PCRE function, i finished the script in no time. :p

That’s evil of course.

So, i create the following script as my apology. I use FoxRate currency converter API. Be careful though, you can not run the script too fast, wait for awhile before sending the next request. That’s what happen when you use a free web service. I guess.

Anyway, it’s 2 a.m in the morning here. Gotto go to bed. Night night.

function convertcurrency($from,$to,$amount)
{
  $xml = "
<?xml version='1.0'?>
<methodcall>
  <methodname>foxrate.currencyConvert</methodname>
  <params>
    <param>
      <value>
        <string>$from</string>
      </value>
    </param>
    <param>
      <value>
        <string>$to</string>
      </value>
    </param>
    <param>
      <value>
        <double>$amount</double>
      </value>
    </param>
  </params>
</methodcall>";

  $url = "http://www.foxrate.org";

  $header  = "POST /rpc/ HTTP/1.0 \\r\\n";
  $header .= "Host: foxrate.org \\r\\n";
  $header .= "MIME-Version: 1.0 \\r\\n";
  $header .= "Content-length: ".strlen($xml)." \\r\\n";
  $header .= "Content-transfer-encoding: text \\r\\n";
  $header .= "Document-type: Request \\r\\n";
  $header .= "Connection: close \\r\\n\\r\\n";
  $header .= $xml;

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $xmlresponse = curl_exec($ch);
  curl_close($ch);

  $sxml = new SimpleXMLElement($xmlresponse);
  $xxml = $sxml->xpath("params/param/value/struct/member");

  foreach ( $xxml as $v )
  {
    if ( $v->name == "flerror" )
    {
      $errflag = $v->value->int;
    }

    if ( !$errflag )
    {
      return false;
      break;
    }

    if ( $v->name == "amount" )
    {
      return $v->value->double;
    }
  }
}

Sample usage:

$ret = convertcurrency("JPY","IDR",1);

if ( $ret )
{
  echo "1 JPY = $ret IDR";
}
else
{
  echo "Wrong currency code or you're too fast to fetch, wait for awhile.";
}
Jun 07

This is interesting,

Java 6 provides the Common Scripting Language Framework for integrating various Scripting Languages into the Java Platform. Most of the popular Scripting Languages like Java Script, PHP Script, Bean Shell Script and PNuts Script etc., can be seamlessly integrated with the Java Platform. Support for Intercommunication between Scripting Languages and Java Programs is possible now because of this. It means that Scripting Language Code can access the Set of Java Libraries and Java Programs can directly embed Scripting Code. Java Applications can also have options for Compiling and Executing Scripts which will lead to good performance, provided the Scripting Engine supports this feature. Let us have a high-level overview of this JSR before going in detail.

Jun 06

apachelog2feed

If you like to follow everything using your feed reader, you might also want to read your Apache log in feed. Well, you need to try Apache Log Analyzer 2 Feed.

ApacheLogAnalyzer2Feed is an object oriented class, written in PHP 5, for parsing/filtering an Apache log file and convert it into feed.

You can filter out which part of your Apache log you’d like to see. For example, you can generate a feed that shows you when Google Bot visit your blog or when your visitor register, etc. See some sample codes here.

Here’s the sample output from my Apache log,


<rss>
<channel>
<title>Log /usr/local/apache2/logs/access_logs filtered by 1 filters</title>
<description>Array
(
    [0] => Array
        (
            [0] => Request
            [1] => regexp:generator\.php
            [2] => IS
        )

)
</description>
<link>/log.php</link>
<lastbuilddate>Wed, 06 Jun 2007 21:20:08 +0100</lastbuilddate>
<generator>FeedCreator 1.7.2-ppt (info@mypapit.net)</generator>
<item>
<title>192.168.1.99 - GET /generator.php HTTP/1.0</title>
<link>/log.php</link>
<description>Array
(
    [Remote-Host] => 192.168.1.99
    [Remote-Logname] => -
    [Remote-User] => -
    [Time] => [06/Jun/2007:21:17:26 +0700]
    [Request] => GET /generator.php HTTP/1.0
    [Final-Status] => 200
    [Bytes-Sent] => 9274
    [Referer] => -
    [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
)
</description>
<pubdate>Wed, 06 Jun 2007 21:17:26 +0100</pubdate>
<guid>b27435fba04c82a72e084d0404bc442b</guid>
</item>
<item>
<title>192.168.1.99 - GET /generator.php HTTP/1.0</title>
<link>/log.php</link>
<description>Array
(
    [Remote-Host] => 192.168.1.99
    [Remote-Logname] => -
    [Remote-User] => -
    [Time] => [06/Jun/2007:21:20:02 +0700]
    [Request] => GET /generator.php HTTP/1.0
    [Final-Status] => 200
    [Bytes-Sent] => 9274
    [Referer] => -
    [User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
)
</description>
<pubdate>Wed, 06 Jun 2007 21:20:02 +0100</pubdate>
<guid>005091851cf9b076180c57ff3c5ea081</guid>
</item>
</channel>
</rss>
Jun 05

php abstract logo small

PHP Abstract is Zend Developer Zone’s new podcast for PHP developers. It was announced on may 17th 2007, but the first episode was just online today.

PHP Abstract episode 1 talks about PHP security tips by Eli, the author of PHP 5 in Practice. It is a short duration talks, but pretty useful.

Link:
PHP Abstract Feed

May 22

Yeah, the first version of PHP4 (PHP 4.0.0) released today, seven years ago.

Who cares about this? Well, Sara did. :)

Mar 17

Many people would love to have feeds on Google search results, like they do on Google news or Google blog search. You can do many thing with this, for example you can build Google search like in your website or blog.

But Google doesn’t show any interest on giving away this feature. Instead they gave us Ajax search API which of course has limitation in number of queries.

It’s just a matter of time until somebody finally hacked this out. All you need is three additional parameters in your query:

  • ch=xxx, xxx is series of checksum numbers
  • output=xml
  • client=navclient-auto

here is the example. And you can see the demo how to use this feeds on you website here. You can also grab the source code here.

This hack is basically derived from previous hack on Google Toolbar which is an extension in Firefox. Someone has figured out the algorithm to generate checksum by looking at the source, and all you have to do is to add output=xml to get the results in xml format.

I have to warn you though, this hack may conflict with Google Term of Services, but it’s still interesting enough to know it.