PHP Blogs

Richard Thomas has a reminder for all of those out there that think frameworks can solve all of the development woes of the world - remember, "frameworks are hammers".

What Framework is the best? What Framework is the fastest? What Framework is the easiest? All of these questions have been asked or answered by pretty much any programmer that exists but what is the true correct answer? [...] At the end of the day any Framework is like a good hammer, it gets the job it needs to do done.

He notes that, while some hammers can do some pretty special things, most of the hammers out there still do the same basic job and do it well. Your choice of framework is more about what you're comfortable with than the fact that you need to make a website.

Abhinav Singh has a recent post to his blog looking at three extensions that you can use to help understand the inner workings of the core Zend Engine.

"PHP tokens and opcodes" - When a PHP script is executed it goes through a number of processes, before the final result is displayed. These processes are namely: Lexing, Parsing, Compiling and Executing. In this blog post, I will walk you through all these processes with a sample example. In the end I will list some useful PHP extensions, which can be used to analyze results of every intermediate process.

He touches on the steps the average PHP script takes in its processing - lexing, parsing/compiling and the actual execution of the opcodes. The tokenizer, parsekit and VLD (Vulcan Logic Disassembler) extensions can help you get down into the nuts and bolts of the language and the engine that makes it work.

Jeez Tech has a new post with a great (and long) list of PHP scripts to connect your application to any number of popular APIs out there.

Do you want to use an API but you are too lazy to write your own code to handle the requests? If you code in PHP as I do, then you will definitely need these classes. By using the classes listed here you will be able of using a great number of web services with an easy and documented way.

They link to libraries to work with the APIs for Alexa, Babelfish, Bing, eBay, Facebooks, Flickr, Linkedin, MSN, Twitter, Skype and Yahoo. They also mention PEAR and the role it plays in the foundation of many web service connections.

Phil Sturgeon has a new post to his blog talking about a way to give your CodeIgniter site a bit more "pep" - use his updated implementation of the Dwoo templating engine.

Not wanting to spend too much time re-inventing the wheel I had a look at existing templating engines and decided to use Dwoo. [...] So after a little head-scratching, we now have CodeIgniter-Dwoo. DwooParser? DwooIgniter? Whatever we call it, my new Dwoo implementation for CodeIgniter sits in with "the CodeIgniter way" perfectly and the only code you will need to change within your application is the Parser file and your view files. No changes to your controllers at all!

You can download the library from the code section of his site.

Latest PECL Releases:

Phil Sturgeon has posted a fun little script CodeIgniter users can use to connect their application with Prowl.

Most web-applications currently use automated e-mail's to let an administrator know someting is going on and some applications use Twitter. Why not use iPhone Push Notifications to get an alert to you immediately without having to check a thing?

He threw together a quick library that only requires a username, password and application name to set the messages. You can download the sample library directly from Github

On the PHPClasses blog there's a new post looking at using the Gearman framework with PHP via a PECL extension.

Gearman is a generic framework to distribute processing jobs to separate processes in the same machine or other machines in a cluster. It allows your application to perform tasks in parallel, balance the processing load, and even invoke code written in other languages. The "Gearman" word is an anagram of "manager". Its purpose is solely to dispatch jobs that need to be executed, but Gearman just by itself does not do anything useful.

In his example he sets up a simple "Hello World" processing queue including the command line to start up the Gearman server and the PHP you'll need to push in a request, grab the status and see the percentage of it that's been completed.

On his TechChorus blog Sudheer has posted his own review of the Packt Publishing book "Zend Framework 1.8 Web Application Development" (by Keith Pope).

The Zend Framework community needed a book covering version 1.8+. Version 1.8 brought new notable features. Zend_Application is one among them. Zend_Application introduced object oriented bootstrapping in applications that otherwise used a procedural script. A bunch of users had difficulty understanding how to set up their applications to make use of the new bootstrapping component. All of them have seem to understand it well now, thanks to support in the official mailing lists and IRC channel.

He looks at the book and how helps to teach some of the fundamentals, like the basics of the model/view/controller design pattern, along with some of the more advanced topics as they walk the reader through the development of an online storefront application. He touches on some of the good points of the book as well as a few things that it could have done better (like the usual editing mistakes Packt is becoming known for). Overall, though, he gives it a good rating.

Michael Girouard has posted a new guide today about getting PHP 5.2.9 up and running on a CentOS distribution:

CentOS in my opinion is the best way to go in terms of server distros. Some people, including myself, are frustrated at the fact that some software is slow to be updated out of a fresh install: specifically PHP. At the time of this writing, PHP 5.1.6 is the version shipped with CentOS 5.4. While I'm sure they have their reasons for this, I still am required to write somewhat modern apps - 5.1 just doesn't cut it anymore.

He suggests moving away from the compile from source option and "go with the flow" and work with the packages that've already been created. You have to get the testing repository set up first (creating a configuration file to add the name, baseurl and other keys) to be able to use the yum installer tool to grab the latest packages.

On the Inside DealTaker blog there's the first part of a tutorial on getting started with the latest revision of the Kohana PHP framework (v3.0).

So you might have read my aricle on frameworks and/or my series of tutorials on Kohana PHP 2.3.x and you are wanting more. Today, I drop the old 2.3.x and bring the new and shiny! So I bring you information to get you started with Kohana PHP 3.0!

The tutorial walks you through the unpacking, installing and configuration of your Kohana setup. They also help you create a simple controller that outputs a simple message on request.

On 10th December the first patch for NetBeans 6.5 was published. You can download the fixes through the IDE's Plugins Manager. The list of fixed issues is available here.


Todays feature is not PHP specific. It works in all files that contain HTML tags. If you open a HTML, PHP or other file in editor, then there is new top bar. The bar displays HTML tag path from root tag to tag where the current caret position is. You probably know this from other HTML editors. 

 If you click on a tag in the bar, then it navigates to the place, where the tag starts.


I will try to explain this feature on an example. In an application there are a few classes that has Draw methods without a parameter.  The classes are Point, Triangle and Circle. In another php file there  is a varibale $shape, where the Draw method is used.

In the case when NetBeans are not able to find out the type of the $shape variable and you want to navigate to the Draw method declaration, then it looks for all Draw methods with the same signature that are available in all classes in the project.  In this example there are tree classes with Draw method without a parameter and all these classes are offered and you can select in which you want to jump. If there is only one class that has the Draw method, then it jumps to the Draw method declaration directly.

For navigation to the Draw method declaration you can place caret into Draw method name and press shortcut CTRL+B or you can use the hyperlink functionality (push CTRL and place mouse cursor over the Draw method name and click). You can also use main menu Navigate -> Go to Declaration or context menu in the editor.

The new feature, which I want to mentioned today, is a functionality that should simplify identifying return points from a method or a function.

As you can see on the picture, when you place cursor into the function keyword in a function or method declaration, then the function keyword and all return statements are highlighted.

The next new feature is code completion for constructors.  After new keyword the code completion windows is displayed with constructors and parameters for all available classes in the project.  

The parameters info functionality works for constructors as well.

This week I am going to write about editor improvements, which are available in the development builds. I hope that I will have time to introduce a new feature every day. The feature freeze for NetBeans 7.0 Milestone 1 was already reached and these improvements will be also available in this M1. If you will try the development builds and run into a problem, enter new issue into Issuezilla  (category php, subcomponent editor).

The first new feature, which I want to introduce is parameter info. When you use a function and you don't remember the parameters you can use CTLR+P shortcut to show the parameters in a small popup window as it is displayed on the picture.

As you can see the parameter is bold that corresponds to the cursor position.

Also if a function has parameters with a default value, then the default value is displayed for the parameter. 



Some people ask me, whether there is available a support for Drupal. The answer is that there is a project on dev.java.net that has the goal to provide support for this CMS in NetBeans. The support is available for NetBeans 6.5 now and you can download the plugin from the project page . If you have any suggestion, write to authors. I'm not involved in this project, but I'm in touch with authors and I'm sure that they will be glad to hear any feedback. 


If you want a different appearance of NetBeans than it is the native one you can simple change the look and feel (L&F). There can be also another reason for changing look and feel due to a bug in Windows L&F. When you are on Windows machine and you use the native Windows look and feel you can run into a problem with focus. Switching between NetBeans IDE and for example Firefox using Alt+TAB and sometimes when switching back to the IDE instead of being focused in the editor where you left it, the menu is focused instead. 

Some  L&Fs are available in Sun Java and many L&Fs are available on internet. Using L&Fs that are in Sun JDK is simple. You should know which Java you use and which version. For example Nimbus L&F is available from Sun JDK 1.6. You can run NetBeans with this L&F in two ways. The first one is running NetBeans from command line with --laf option. This way is sufficient, if you want to just try a L&F. So on *nix OS it's :

/path_where_netbans_are_installed/bin/netbeans --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel

The second way is put the --laf option to the netbeans.conf file. The netbeans.conf file is located in etc folder in NetBeans installation folder. Open the netbeans.conf file and add the option into netbeans_default_options. When you do it in this way, then it's permanent and NetBeans will always start with this L&F.

There are a few screenshots of NetBeans with some L&F, which are available in Sun JDK 1.6.

Nimbus: --laf com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel

Metal: --laf javax.swing.plaf.metal.MetalLookAndFeel

GTK: --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel

As I wrote above, we are not limited only with L&Fs, which are available in a JDK. You can dowload different L&Fs from net. Some of them are open source and free, but there are also commercial. If you want to use such L&F, you have to download a jar that contains the L&F definition and put it on NetBeans classpath. When you want to try a L&F on the command line, then you run NetBeans also with -cp:p path_to_L&F_jar option, which adds the jar on the NetBeans classpath. For example the command for using Liquid L&F will be:

/path_where_netbans_are_installed/bin/netbeans --laf com.birosoft.liquid.LiquidLookAndFeel -cp:p /path/to/liquidlnf.jar

You can put both options into default netbeans_default_options in netbeans.conf file, if you want to use command line.

There are a few examples. You can download the jar from the projects page and play with them.

Liquid: --laf com.birosoft.liquid.LiquidLookAndFeel -cp:p /path/to/liquidlnf.jar

Napkin: --laf net.sourceforge.napkinlaf.NapkinLookAndFeel -cp:p /path/to/napkinlaf.jar

NimROD: --laf com.nilo.plaf.nimrod.NimRODLookAndFeel -cp:p /path/to/nimrodlf.jar

Quaqua: --laf ch.randelshofer.quaqua.QuaquaLookAndFeel -cp:p /path/to/quaqua.jar

If you find a nice L&F, write me, I will add the screenshot here.

A build tool can be used for automated actions. For example if you want to have continual build and run tests, building documentations, create a production builds, deploy on a staging or production server etc. One of such build tools is Apache Ant, which  is a Java-based build tool. You can use this tool also together with your PHP projects. The NetBeans PHP distribution is probably only one distribution, which doesn't contain the Ant support by default.

Adding Ant into the IDE is very simple. Open the plugin manager (Tools->Plugins) and on the Available Plugins tab in the Search dialog write ant. After this, you should see similar picture to:

Check the Ant item and click on Install button. After accepting the license, the needed module are downloaded from the update center and installed. If you have already an ant file in your project it should be after the installation recognized.

Although the Ant files are xml files, they have a special icon in NetBeans. You can expand the node that represents the Ant file in explorer and the subnodes are the targets defined in the script. You can run single target and also you can assign a shortcut for a target through the context menu over the target node.

The editor offers code completion for Ant tags and also for their attributes. You can also validate and check whether the file is well formed.

There is one limitation in PHP distribution. The PHP project doesn't allow to create Ant files through a wizard. So you have to create new well-formed xml document. The root element has to be <project>.

Does someone from readers use Ant together with PHP projects? Do you use a building tool? Which one?

Last week's news, but NetBeans IDE 6.5 final release went out last week. The multi-language version was shipped at the same time, which is a NetBeans first! You can get it at http://www.netbeans.org/downloads.

For the latest PHP features like SFTP support, Symfony support etc--the stuff the guys on this blog are talking about--you'll need the nightly dev build.

I have started to work on the Symfony support. In this time I'm evaluating, what we will be able to implement, how the support should be done, and what will offer to the developers. 

Question for Symfony developers: Which productivity features should be a part of such support? I need to know the usecase, when you need a feature, understand the workflow etc. I hope that information from you help me to design useful support.

Is there any tool which support developing PHP applications based on Symfony framework?

I created the second part of the demo, where I talk about the PHP distribution of NetBeans 6.5. This part is about basic editor features. 

In the next part of the demo I will concentrate on the PHP editor features.

Today NetBeans 6.5 has been released. The main page at NetBeans.org site was changed and point out that the new release can be downloaded. I have mentioned many times that NetBeans 6.5 is the first release of NetBeans which supports the PHP development.

Although the support for developing PHP applications is new and young, I hope that it will be useful for many PHP developers and for the PHP community too. I would like to say thanks to all people who contribute to this release and also thanks to you, who provides any feedback here or on the users@php.netbeans.org mailing list.

We did the first step. In front of us there is long way to fit as much as possible, what you need as a PHP developer. This first version was influeced by your requests and suggestions and I hope that we will continue in this cooperation and that the community around this PHP support will grow. Thanks.

Recently, many of you asked for not only FTP support but also SFTP - yesterday we fulfilled your wish so everyone can easily try it now. Of course, one has to download the development version of NetBeans or wait for the first milestone of the next NB version (after NB 6.5).

Meanwhile, let's setup and use our first SFTP connection...

1. Create a new SFTP connection - create a new Run Configuration (Remote Web Site) and Manage Remote connections.

Create a new connection

Creating a new SFTP connection

2. Provide all the details and test the connection.

Testing SFTP connection

3. Try to upload some files.

Upload file

4. And watch the log if everything goes fine...

SFTP log

5. ... and your files are successfully stored on your server.

SFTP log

6. That's it!


As you can see, the behaviour is the same like for our FTP support so nobody should have any problem with it, I hope. And of course, like every time, please, let us know how you enjoy it and whether it works for you (if not, please report all the issues or enhancements to our IssueZilla, component PHP, subcomponent ftp_support).

Thanks a lot.


A new screencast  is now available on NetBeans TV: Building a Flickr slideshow with PHP. This demo shows off the new PHP features of NetBeans 6.5 by walking through building a simple application to access Flickr.  You will then see how to turn your Flickr images into a simple slideshow using JavaScript and CSS.

Thanks to Justin Bolter for this screencast.

At the end of October I attended the International PHP Conterence 2008, where I had presentation about the PHP support in NetBeans. You can read more about the conference here at this blog. A few people asked me for creating a screencast about the demo. There is the first part, which is about the PHP project and run configurations. 

The next part of the demo will be about the editor features.

Today I have committed to the trunk small improvement of generating getters and setters for class properties. It's based on your suggestion and as you can see on the pictures, you can select the way, how to generate the getter and setter method name.

There is a new combo box that contains two items which display the result of the method name for the first class field. On the picture you can see that you can select between two ways. The first one is the way which is used in NetBeans 6.5 and the second one is with underscore between get/set and property name.

There is the first question: Does somebody use different form of the getter and setter name? If yes, please speak up and I will update the dialog.

The enhancement is not fully finished. The value of the combo box now is not remembered, but I will add functionality, which will remember it per project. So the second question is: Do you use different form of getter and setter method names in different projects? Or you use just one way? Should be project or global options?

When I tested the enhancement then I have thinking to add also option for generating Php doc stub. But I haven't time to finish it yet.

I have played again with performance of the NetBeans PHP IDE. For this purpose I have created "PHP code generator" that generates php files with classes, which create large class structure. Still it's somehow artificial, but for testing purposes the generated sources are good and valid.

I did some measurements on Core 2 Duo 2 GHZ machine. I generated php files for four projects as you can see from the result table. I have switch off the Task list window and measured the time of the creating project with the initial indexing of the php files in the project. The initial indexing parses all files in the project and store information about the files in a cache. Basically the features like code completion, navigation etc. don't work directly with the files, but with the information from the cache. The time of the initial indexing is in the second column in result table. It can be increased when you allow to NetBeans to use more memory than is the default value. In such case the garbage collector doesn't have to run so often. For example when I have increased the memory for NetBeans to  512MB then the indexing of the project with 15 000 files was about one minute shorter.

Number of PHP files
Initial project indexing
Opening indexed project
Responsiveness
 2 500  34 s
 2 s
 OK
 5 000  75 s
 3 s
 OK
 10 000  258 s
 4 s
 sluggish
 15 000
 395 s
 5 s
slow

The third column contains times that the IDE needs for opening a project. Because the cache is stored on HDD, the IDE check during opening project, whether the files were not changed externally to keep informations in the cache up-to-date.  As you can see the times are very small.

The last column contains my feeling, when I tried to add a method into a class and navigate through the sources. Working with project with 5 000 files was OK and the slowdown of responsiveness wasn't significant. When I work with the project with 10 000 files, then the IDE was slow sometimes during opening files and I had to wait a while (1 - 3 seconds) for code completion in the top level context. Working with this project wasn't so comfortable like with the project with 5 000 files. Similar situation was, when I try to work with the project that has 15 000 php files. The hyperlink functionality still works great, but using code completion in the top level context needs some patience.

I was evaluating why the IDE is slower with big projects and I  think that there is chance for improvements. If you work with such big project, I recommend to switch off the Task window, which can slow the parsing and opening projects.

I have one question for you. How many php files do you have in your projects? I would like to know, how big are the real projects.

NetBeans 6.5 doesn't have direct support for generating PHP documentation. Here is a trick how to do it. Basically I use a new Run Configuration that calls a small script to generate the documentation. I did this on my Ubuntu machine, but Windows users should be able to reuse the steps.

At first I downloaded the PHPDocumentor itself from the project pages, unzipped the zip file and change the rights of phpdoc to be executable.

For the next step I created a new bash script which I call from NetBeans. You can write the script directly in NetBeans. NetBeans PHP distro  includes very simple syntax coloring support for bash script and bat files as well. The picture below displays NetBeans PHP RC2, showing my phpdocNB.sh script that I use for generating the documentation.

The text form of the script:

#! /bin/bash
# Script for generatig php documentation from NetBeans through run configuration

PATH_TO_PHP_DOCUMENTOR=/space/php/phpdocumentor/PhpDocumentor
$PATH_TO_PHP_DOCUMENTOR/phpdoc -d $2 -t $3
echo "Generating PHP Documentation finished ..."
firefox $3/index.html

As you can see the script is very simple. If you want to use it, you should just change the value of PATH_TO_PHPDOCUMENTOR variable to pick up the phpdoc script from your location. Through the -d parameter you define which directory will be parsed (and subdirectories) and -t parameter says in which directory the PHPDocumentor should create the documentation files. When the generation of the documentation is finished than the result is opened in new Firefox tab to check the result.

Now, when the script is done, I need to call it from NetBeans. As I have mentioned we can use for this new Run Configuration. There are three ways how to display Project Properties dialog where you can create it. You can select the project node and in the context menu over this node invoke Properties item or from main File menu choose Project Properties item or in the main tool bar there is combobox with already existing configurations and the last item in the combo box is Configure... item. The combo box in the main tool bar is a way how to quickly switch between configurations.

So in the Project Properties dialog click on the Run Configuration category and create new configuration through the New... button. I have named the configuration PHPDocumentor. In the Run As combo box select Script (run in command line) item. Uncheck Use default PHP Interpreter and browse the created script. As the first argument put the path of your project sources. You can copy the path from the Source category panel, Source Folder text field. As the second parameter put a path, where you want to generate the documentation. The folder doesn't have to exist, the PHPDocumentor will create it. The picture below shows my PHPDocumentor configuration.

NetBeans will put for the script as the first argument the Index File, when you run project with this configuration or the file for which you invoke Run Single File action. This parameter is in my script simply ignored and always the documentation is generated for all sources.

Now when I choose the PHPDocumentor configuration in the combo box in the main tool bar and run the project,  then the documentation is generated and the result is opened in new Firefox tab.


You can improve the script and add more parameters, it's all up to you. I know that this is not the ideal support of PHPDocumentor, but for the next verion I want to make the real integration. If a Windows user out there will write the bat file, could you please attach the file in a comment, and I will alter this post.

This is not really hot news, but I haven't time to write about it yet. The Release Candidate 2 was published on Thursday, but if you missed it you can download the build from here. If you want to know about available features (not only the PHP one), you can read here.