Tag Archives: php

Working on existing PHP applications

10 Jan

We’ve all been there before, you’ve been hired to finish / work on someone elses work, and you encounter some very strange behaviour. If you’re working on a small website, going through the code should provide you with the necessairy information to solve this issue, however, if the application is somewhat bigger (multiple components, databases, caching, dynamic code building, multiple objects …) it’s always nice to know exactly what code is being executed on a certain moment.

Imagine you have found the exact page / function / action where it’s going wrong, and you are trying to debug it. Commercial companies offer solutions like Zend Platform / Zend Studio to debug, view stacktraces, variable watches & alot more…and i am mostly using Zend Studio for that too, but at this moment in time, Zend does not offer a windows library for Zend Platform that supports PHP 5.2.0, neither did they release a fix for Zend Studio 5.5 to build inspectation data over a Samba share…So let’s do the same thing using XDebug, afterall the world still spins without Zend.
Make sure to get the right windows or linux module for your php version from www.xdebug.org and use the installation instructions to get it running, make sure to check phpinfo to see if the xdebug is loaded. When everything is installed, we’ll start by profiling a certain action to find out what exactly the page/action is doing. Make sure to adapt your php.ini with the following configuration :

zend_extension_ts=”c:/apache/php/ext/php_xdebug-2.0.0rc2-5.2.1.dll”

[xdebug]
xdebug.remote_autostart=1
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.profiler_append=0
xdebug.profiler_enable=1
xdebug.profiler_enable_trigger=1
xdebug.profiler_output_dir=c:/temp/
xdebug.profiler_output_name=profile

After that restart your apache, and open the page you want to analyse. As soon as you send a request to the webserver it will create a file in the c:/temp (or whatever path you defined). For me it generated a file (c:/temp/cachegrind.out.5808). This file contains alot of information what exactly php was doing on your request. Call it a stack trace. This file is human readable but does not give an immidiate overview, that’s why i would suggest to use a program to analyse the cachegrind. To my knowledge, the best program to-do that is KCacheGrind, the downside is that is a KDE program, so if you are using windows you would need alot of hacks, just to get KCacheGrind running, thats why there is a windows port (with less features) available called WinCacheGrind. If you open WinCache use the File>Open File dialog and relocate to the cachegrind.out file (for me c:/temp/cachegrind.out.5808), depending on the size of your file, wincachegrind will start analysing and give you a visual representation of the stack trace of your action.

Note that all pages you visit from now (untill de-activating the module in php.ini) will get ‘profiled’ and generate a cachegrind file. As this is filesystem intensive, i would suggest commenting the above php.ini section as soon as you’re done and restart your webserver.

Zend Studio Performance

8 Dec

Lately i noticed Zend Studio wasn’t running as smooth as before. When going into hibernate or logging off, i often notice javaw.exe has crashed, that caused the system not to shut down. To fix this problem i’ve found several solutions, i’ll list those here for future reference :

  • make sure the power settings do not use the option to enable cpu throttling (this seems to be a java issue)
  • try replacing zends jre by JRE 6 (http://java.sun.com/javase/6/download.jsp)
  • disable the OS look&feel in your zend application
  • disable all power management for your video card
  • if you are using a dual monitor setup, make sure the editor & palettes are on the same monitor/display
  • remove the Zend Project cache file : /Documents and Settings/{Win username}/ZDE/config_5.1/caches/
  • expand the heap sizes (to more then 256 MB) the JRE needs for the Studio to function [file: {studiopath}/bin/ZDE.lax]
  • if you have a 64b machine, make sure you have the 64bit java lib
  • try disabling your antivirus for a second and check if performance goes up
  • if you are using an external subversion client (not ZDE’s), make sure your options in ZDE are on CVS. (options > source control). Performance gets a huge boost (integrated svn is causing a problem when using 3th party tools)
  • submit a support ticket (http://www.zend.com/support) (make sure to mention you tried all t he above steps, and provide as much detail as possible, because they won’t fix your problem untill they have everything they are looking for : hardware, software, ZDE.log, description of the project)

Here’s the info I found posted over at the PhpBuilder.com Zend Studio Forum by MStaniszczak (post is no longer there). This item addresses the speed of the java virtual machine, and for those of us running Intel processors, this tends to be faster than the Sun JRE. If you’ve got an AMD processor, this may or may not yield any performance.

Head on over to BEA Systems and get the JRockit 5.0 JRE. Don’t worry about the SDK, unless you’re a Java programmer. It’s about 30 megs, so dial-up beware. After downloading it, extract the exe (right click, extract archive).

After you’ve done that, you should see some files, as well as another archive or zip file named something like win_ia32_jrockit150_04_jre.zip. You’ll want to extract that as well, to it’s own directory or folder (name it jre) , and that’s going to be what we need.

First, make sure the ZDE is not currently running. If it is, exit it. Now, find your installation of the Zend Studio client. It should be something like C:/Program Files/Zend/ZendStudioClient-5.0.0/. You’ll see a directory already named jre. Rename it to jre_old. Copy the directory we created from the archive into the ZendStudioClient-5.0.0/ directory.

For me the HEAP size, in combination with the source control tab (to cvs) did it, as i am using tortoisesvn for version management.

Writing Killer PHP Applications

31 Oct

Because i still have a quite visited blog (disabled comments though), i will try to post some web development idea’s / articles on a regular base. As a full-time webdeveloper i find it very important to have the right tools. I’ve told you before, as a development machine i am still using a WAMP set-up (Windows, Apache, Mysql, Php), whenever i finish some work on a project, i commit the code changes to a subversion repository (running on a Debian machine). The subversion server accepts connections over secured http to make sure no-one is reading / sniffing. To my opinion, the best tool to handle your svn actions (merge, commit, update) on a Windows platform is TortoiseSVN, they release regular updates, supports almost every svn action and has great documentation.

The most important in my daily development is my IDE, for the last three years i have been using Zend Studio Professional, at this moment i think (and i’m pretty sure), it’s the best PHP IDE Around. It has debugging capabilities, code completion, svn/cvs integration (although i prefer tortoisesvn, see above), but ofcourse it can’t be perfect…(i do expect it to come close for 300$/year).
One thing i don’t like about the Zend IDE (besides the pricing), are the updates. Zend is quite slow on the updates, (they might have too much todo), but as a registered & paying customer, i think some major fixes (Javascript errors in internal browser, Linux Visual Interface, Crashes) in Zend Studio 5.2.0 have a higher priority then deciding to build a new IDE when the current one is not finished (it never is). Nevertheless, this IDE is still the best PHP Editor around, in combination with the Zend Platform (free for developer licences & combined in the Zend Pro licence) you’ve got yourself a kickass debugging system containing the most important features as breakpoints, watches, stacks and output buffering.

Quick Post / Hiring

16 Oct

Hi all, it’s been awhile. I enjoy life as an independant consultant. It’s my second month fully independant (fulltime), and i’m loving it. Infact, new projects are coming in too fast, so we’re hiring.

We are looking for young skilled Belgian (dutch speaking) web developers. If you are interested send your CV to me at snk00sj@digitalbase.eu Before you do that, make sure you have the following qualifications :

  • under 35 years/old
  • native or perfect dutch speaking
  • decent knowledge of english
  • good social skills
  • excellent PHP knowledge
  • basic knowledge of version management systems (cvs, svn)

Make sure to mention your references and/or degrees.

Talk to you soon

Internationalization – seo – mod_rewrite : Part II

2 Aug

As a follow-up to my previous post (Internationalization – seo – mod_rewrite : Part I). If you followed my previous instructions, by now you should be the proud owner of a ‘google sitemaps‘ account and your webhost supports statistics that can tell you when a crawlbot visited your website (or raw logs, if you’re a sherlock holmes type).

Because you are reading this howto, i can conclude you have a website running on a domain or atleast a subdomain. For multi-language systems i prefer using the subdomain to set the language of the user. So if you were using www.mydomain.tld/index.php?lang=en before, you will now be using en.mydomain.tld. For a website with multiple languages that would become :

  • www.mydomain.tld : would point to the default language, or will relocate the user based on browser/os/nslookup (whatever you prefer)
  • en.mydomain.tld : would point to the website in english
  • fr.mydomain.tld : would point to the website in french
  • X.mydomain.tld : would point to the website in …

If you are using a subdomain this could be done with en.subdomain.mydomain.tld etc….
This way of working has some advantages :

  • users will be able to bookmark directly in their language.
  • Search engine optimalisation can be targetted on subdomains seperately
  • crawlbots will easily know which language they are crawling (also due to tag)

Step 1 : Set up your nameserver records

Make sure the A records all point to the same adress, i prefer setting a records for all different languages as i do not want to point *.domain.tld to the website (for various reasons). As this is not a dns administration guide, try to find more information in the docs of your dns daemon, but before doing that check if undefined subdomains do not already point to the same ip as your main domain, this could be the case and then no configuration is needed…

You can check this by doing :

 ping mydomain.tld

Compare the result ip adress with a ping to a subdomain :

 ping en.mydomain.tld

If both ip match, you will most probably have the right nameserver configuration already, you can go straight to step 2.

Step 2 : Make sure the webserver catches the subdomain

As i am using apache only at this moment, i will only explain you briefly how to do this in apache, for all other webservers check the documentation. Try to look for the virtualhost directive of your domain in the webserver configuration, by default this will be in /etc/httpd/conf, searching for httpd.conf, apache.conf or apache2.conf will tell you where it’s located…If you split up your virtualhost directives in different files, you are most probably clever enough to find your virtualhost directive, if you didn’t check the bottom of your configation file, there should be something like this :




  ServerName yourdomain
  DocumentRoot "/path/to/your/webroot"
  DirectoryIndex index.php
  
   AllowOverride All
   Order allow,deny
   Allow from All
  

Add a serveralias, so apache knows to catch the subdomains, there are 2 ways of doing this, you can add a ServerAlias for all different languages, or you could add a * alias, so from now on apache will catch all unknown subdomains for this domain.

Option 1 : Catch only the subdomains i want




  ServerName yourdomain
  ServerAlias language1.yourdomain
  ServerAlias language2.yourdomain
  DocumentRoot "/path/to/your/webroot"
  DirectoryIndex index.php
  
   AllowOverride All
   Order allow,deny
   Allow from All
  

Option 2 : Catch all subdomains




  ServerName yourdomain
  ServerAlias *.yourdomain
  DocumentRoot "/path/to/your/webroot"
  DirectoryIndex index.php
  
   AllowOverride All
   Order allow,deny
   Allow from All
  

Save your virtualhost config file, or main webserver configuration file and restart your webserver

 apachectrl -k restart

More information on setting Apache virtualhosts serveralias’es.

You should now be able to see the same website you had before, using the lang.mydomain.tld subdomains, if this is not the case, check your include paths etc….I have to stop this howto for now, we will go the the coding itself in Part III

Internationalization – seo – mod_rewrite : Part 1

10 Jul

I am running a pretty big company website that uses multiple languages so users can browse the website in their language. Lately i have been working on the Search Engine Optimalisation, and i noticed google (and some other crawl bots) do not correctly crawl the other languages, this had something todo with various reasons :

  • language selection was saved in session or by $_GET argument
  • meta language tag was not always set
  • there was no clear line how the language was selected, user couldn’t see by url which language he selected

I did a few lookups on the internet, some various SEO forums, and i’ve collected this information and, with the help of Apache mod_rewrite, turned the website into a fancy, easy-to-use, multilanguage environment, and this is how i did it. I will explain you in 3 different parts, which i will try to finish in the upcoming 3 days….

To start off i am using .xml files to hold all the different language strings, nowadays you can find some php frameworks that fully support i18n, but back in the days i was making international websites, they were not that commonly available. If you would go for a framework i would choose Mojavi, Prado or Symfony, i am not going to elaborate on that, as this post is not about frameworks, but howto put different languages on your website, and making sure google (and other search engines), crawl em like they should….

Start off by making sure you have a google sitemaps account and have a way to gather website statistics, very good would be a package where you can list the crawl bots seperately (i prefer awstats)

Sitemaps what/where went wrong when crawling your site. The Google Sitemaps program has two major components:

I’ll leave you the time to make sure you have both of the above items + it’s a really nice excuse to stop writing and do something else…Part II soon…

Awstats

Another Development Week

3 Feb

At this moment i am managing a project with 3 programmers and a designer. Because of the deadline of the project i had to allocate some extra resources to make sure everything is finished in time.

We are creating a system to analyse “Post Construction Waste” that is being transferred in Europe. To satisfy the need of our customer we designed a [tag]framework[/tag] that uses some of the most recent technologies including ajax, output caching, templating, xml language parsing and more…Because i prefer working with the recent available technologies, we decided to develop the project in php5, mainly because of the new/extended oop features and exception handling.

For version management we use Subversion, on my windows machine powered by TortoiseSVN with some extra scripts to commit/update/export with a simple click of the mouse (or shortcut combination). I noticed this week we crossed revision 700, we passed the cape of 500 programming hours on this project too….Time to move to the next one ?

Prado v3.0 alpha edition is out

25 Jan

I just got a very nice email concerning the release of an update of my favourite MVC php framework.

We are very pleased to announce that PRADO 3.0 alpha version is now available for downloading. Please use PRADO v3 discussion for topics about this v3 alpha release. We are working on a new website at pradosoft.com which will be available upon v3 beta release.

I got the 3.0a version just 5 minutes ago, because i am starting a new project with another user registration / signup, i decided to give prado a shot. Very nice is the v3 quickstart tutorial, the guys over at xisc realize how important it is to have good user documentation / sample applications.

I used prado v2 before to develop a small intranet, and back then the petshop example (available by CVS) helped me quite alot trying to figure things out…and it seems like they are putting a big effort into documentation once again. Another big advantage is that prado has a good / friendly community, decent questions on the forum get a fast reply, and also developers are hanging around to help people as much as possible, keep up the good work guys ! i’m with ya !

Go get it over at xisc.com

AJAX Frameworks

24 Jan

Cajax :

A PHP class library for writing powerfull reloadless web user interfaces using Ajax (DHTML+server-side) style.

Homepage : http://sourceforge.net/projects/cajax/

On the first view i can’t seem to find a webpage or online documentation, now that’s a bad start. Because there are alot of AJAX frameworks available, i decided to let this one go…i had a look at the sourcecode, some examples included but besides a README.developer file i prefer some more documentation…

AjaxAC

AjaxAC is an open-source framework written in PHP, used to develop/create/generate AJAX applications. The fundamental idea behind AJAX (Asynchronous JavaScript And XML) is to use the XMLHttpRequest object to change a web page state using background HTTP sub-requests without reloading the entire page. It is released under the terms of the Apache License v2.0.

Homepage : http://ajax.zervaas.com.au/

Also not much documentation, three nice examples are online on their homepage, one example with similar functionality as “Google Suggest”. I downloaded the source file, in total the lib comes down to 56kb (example excluded), all bundled in one big class file with 3 dependencies, i am still playing with the examples to see how this framework works…i’ll keep u posted

XAjaxÂÂ

Ajax-enable your PHP application with a simple toolkit that gets the job done fast.

Some very nice examples online, including a signup form (thats exactly what i needed), i’ll give it a try and let you guys know what i think about it

PHP Form Handling

24 Jan

Goodbye page refreshes, goodbye “post page” before being able to check the inputted data. Nowadays the life of a webdesigner is alot easier because we now have AJAX !

In the “old days”, the way to check form input was to send it to the server using a POST/GET method, then verifying the data and send the user to the appropriate page, depending on the validation of the input. This way of form validation works for everything you want todo, but with larger/more detailed forms you will soon realize that it’s very hard to maintain & extend, and then we’re not talking about the end-user annoyance.

On the internet you will see dozens of AJAX frameworks, websites using AJAX. The best example of this all is Google suggest, type in a keyword and instantly get the number of hits google found for your keyword, no need to refresh, no need to click a button…it’s magic isn’t it ?
But this **** is al over, we’re past that now! some really smart people came up with a thing called Asynchronous JavaScript And XML aka AJAX . The intent is to shift a great deal of computation to the Web surfer’s computer, so the entire Web page does not have to reload when a change is made due to user interaction. Using this technique, webdevelopers can create dynamic forms that instantly check the users input and take appropriate actions after.

In the upcoming posts i will give some AJAX frameworks a go, because i need to find a good way to check the form input on a new website i am developing, the first one that i run into that is easy to use, extendable and fits my needs will be my last post on this matter (for now)….