PHP and Scalable Vector Graphics

If you are looking for a great way to dynamically generate complex graphics with PHP, look not further than scalable vector graphics (SVG). For those not familiar with SVG images they are essentially a XML structured image file (currently with the help of an SVG viewing plugin from Adobe). Here is a little article regarding PHP and SVG from Zend.
http://www.zend.com/zend/trick/tricks12apr.php

SQLite and Choosing a Database Abstraction Layer

So, have you heard of this new SQLite embedded database? I was just reading about it the other day.

SQLite is a C library that implements an embeddable SQL database engine. Programs that link with the SQLite library can have SQL database access without running a separate RDBMS process.


Apparently they are going to implement it in the next version of PHP. This is a good thing. Sure, it will be slow and simplistic, and probably not very scalable for heavy use, but it has one thing going for it: distribution. Every PHP installation will have it. Have you ever been writing a program that will be distribute to multiple clients and worried that they won’t have the right database installed? or any database installed? Soon you won’t have to worry, because as long as they have PHP, they will have SQLite.

So now the possibility of using this in the future on servers that aren’t my own has intrigued me. And I’m already intrigued by some of the other free databases out there. I’ve heard PostgreSQL development is really doing well and more and more people prefer it to MySQL. I’ve also heard a little about some new database called Firebird or something like that. So… why am I still coding all my PHP applications with mysql_query() functions? Why am I not using a database abstraction library so that I can easily use my applications with any database I choose? That’s a very good question. Maybe I’m stupid, or simply too lazy to try something new. I’ve thought about it a lot over the past few weeks. I think my biggest fear with choosing a library to use is standards. I know that the built-in mysql functions are going to be around for a while. I don’t know if I can say the same thing about some of these database abstraction layers. Some might claim that PEAR DB is the standard since it comes packaged with PHP. But there is also another called DBX that comes with PHP. So does that make it the standard too?

I just read an interesting forum thread where John Lim, author of ADODB, claims that PEAR DB is obsolete and the new versions are breaking backward compatibility.


Tomas worked hard on PEAR DB, but it was made obsolete by PEAR MDB. It would not have been too much trouble to make MDB compatible with PEAR DB. ADODB has a PEAR DB layer, but Lukas (MDB lead) decided against it. In fact, they are still releasing PEAR DB as the default abstraction layer, so more people are going to hate the switch when MDB becomes the default standard.

Now Lukas has decided that MDB 2.0 will break MDB 1.0 compatibility.

I think Lukas is a smart guy, but i don’t think it wise to treat API’s as toys to play with, particularly if you want to bet your company’s products on a software library.

http://news.php.net/article.php?group=php.pear.dev&article=17793

So long as PEAR remains a coders playground, depending on PEAR does not mean that anyone is looking after your interest either.


Maybe John Lim is just trying to get people to use his product, ADOdb, instead. But if what he says about PEAR DB is true, then thats a big “STAY CLEAR” sign to me. I’m already going to have to rewrite thousands of lines of code if I decide to switch to an abstraction layer. I don’t want to have to do it again each time they come out with a new version. That’s exactly what I am afraid of.

One thing is clear to me. I need to pick an abstraction layer soon. I’m starting new projects all the time and the longer I wait the more code I will need to rewrite later. So which to choose? Right now I think I’m leaning toward ADOdb. It is very fast, easily portable, supports almost every database out there, and has many features above and beyond what I’m used to. I’ve also been watching it for about a year and new versions are released often, but never break backwards compatibility.

Anyway, what are your guys thoughts on this?

SOAP and PHP; now on phppatterns

Like him or not (I personally do), Harry Fuecks always has pleanty of great info on his site: phppatterns.com. There is no exception this week. He has just posted a flury of articles on using php to write SOAP/WSDL clients, SOAP servers and all kinds of other sudsy goodness. Read more for the direct links, or just go to his site: phppatterns.com

Mixed output and timing

Right, so I learned to code mixed html/php the sloppy way, switching back and forth whenever the mood struck. Lately, I’ve been realizing what a pain it is to figure out what’s where when something needs to
change…. so I switched to just putting all my output into a variable, then outputting it in a pesudo-template at the end of the script.
I’ve started working with larger datasets, so I added a timer function to display the time it took to generate each page in the footer…. I ran my old page a few times, and saw consisted 4+ second generation times. I changed it to the pseudo-template, and I’m getting consistent .2 second times.

I also read of a difference in using
“stuff $php_variable stuff”, which is slower than
“stuff ” . $php_variable . ” stuff”, so I changed that where
appropriate as well. Additionally, ‘stuff’ is also faster, but by a neglible amount.

Here’s the old code:
[code]
while ($myrow = mysql_fetch_array($result)) {
if (mysql_errno() != 0) {
echo “Error ” . mysql_errno() .”

“;
} else { // end if (mysql_errno() != 0)
?>


“;
} else { // end if (mysql_errno() != 0)
$out .= “

“;
$out .= ”

” . $myrow[“id”] . ”
“;
$out .= ”

” . $myrow[“title”] . ”
“;
$out .= ”

” . $myrow[“artist”] . ”
“;
$out .= ”

” . $myrow[“bpm”] . ”
“;
$out .= ”

” . $myrow[“genre”] . ”
“;
$out .= ”

” . $myrow[“stuff”] . ”
“;
$out .= ”

“;
} // end else
} // end while ($myrow = mysql_fetch_array($result))
[/code]
This was for about 425 rows, I believe.

I had no idea it made THAT much of a difference… Guess I’ll be using that on everything now… If not switching over to SMARTY or some other true templating system.

Free PHP IDE w/ Debugger

There is a new free PHP IDE available from a company called Maguma. It is for windows 98, Me, 2000, and XP. If you download the complete version it installs PHP 4.3 on your machine and it adds debugging functionality to the IDE. Sounds pretty nifty. I downloaded it the other day on my home computer but haven’t really tried it out yet. If anyone is looking for a free PHP development program with advanced functionality you might want to try it and let us know what you think.

PHP CLI Ncurses

Link: Using Ncurses in PHP

PHP Command Line Interface has made some vast improvements over the past few months. One of which is Ncurses functionality. I read this article at Zend.com and thought it was very cool. It allows you to format the text on the screen. The article has screenshots to help you understand what it really does.

Before everyone tackles me for using PHP for shell scripts, I’d like to present my reasoning. Sure, even with the advances PHP has made recently, PERL is still probably a better option for shell scripting. Quite frankly, I don’t have the time to learn all the ins and outs of PERL just to write a simple script to dump some database records. I already know how to do that in PHP, so why not use PHP? I think sometimes people underestimate the value of having one language that can do everything you need. It keeps syntax confusion to a minimum and allows me to study the more advanced aspects of the language instead of just knowing the basics of multiple languages. Not to mention it cuts development time by ungodly margins.

I urge you to give PHP a try for shell scripts (That is, unless you are already a PERL god, which I am not).

All menu-based sites covered by SBC patents?

Interesting legal case, as [url=http://www.sbc.com]SBC[/url] (we should DOS them) claims that they have the [url=http://www.theregister.co.uk/content/6/28985.html]patent rights[/url] to any frame or menu based navigational system. Appearantly, they are requesting [url=http://www2.museumtour.com/sbc.html]royalty fees of 2%[/url] of total revenue of any site that uses such navigation methods.

Not happy with the street smarts of their legal counsel. When will they learn?