Archive for the ‘PHP/MySQL’ Category

New Website for Activo:

November 23rd, 2010
Comments Off

I have good news and bad news to tell you, well it is not really bad news, but just wanted to use that saying…

The bad news is that this website is has just become absolute. Meaning we will no longer publish anything new or introduce any new content on this website. The good news is that we already have a new website and the new website can be found at Notice that we got the domain name that we always wanted to have for Activo – Yeah!


For those of you who are interested, the new website was launched in late August of 2010. The domain was purchased back in November of 2009. The site currently already have twice the amount of traffic that this website has. The site also reflects a few changes in Activo:

  1. We moved our offices from Santa Clara to Los Angeles – and we love it down here. In fact LA is a great hub for techies and entrepreneurs, believe it or not.
  2. We now have a virtual team of developers, designers, and project managers. Yes – it was a decision we had to make back in the days before we moved and it turned out to work great. Our customers love it.
  3. We have decided to focus on Magento Development and Magento Extensions. I got to say, what a great decision that was!

So, check out the new website and our new blog. I (Ron Peled) will continue to post regularly about our daily grind and share with you as much as possible from what I am doing at any given time. Drop me a line if you have any suggestions or recommendations.

.NET Framework, AJAX, Content Management Systems, eCommerce, Ektron, Joomla, LAMP: Linux Apache MySQL PHP, Magento, Performance Optimization, PHP/MySQL, Project Management, Search Engine Optimization (SEO), Web Application Hosting, Web Design, Web Development, Web-based User Interfaces, ZenCart

Method Overloading Workaround in PHP5

June 25th, 2009
Comments Off

This past week I had the need to use overloaded methods in PHP 5. Overloading a method in object oriented design is especially helpful when trying to achieve the same operation while the code needs to be triggered from different states of the application or even different locations of the application. In my case, I needed an overloaded constructor to a PHP class. Yes, constructors are also a bit different in PHP 5 but still workable.


To make a long story short, in PHP 5 there is no real way to overload a method like you can with Java. However, it seems like the developers of PHP 5 did have overloading methods in mind and allowed some form of it. It seems like allowing a real method overloads in PHP would be a special case of what the core developers actually allowed to do. The reason behind the current syntax is beyound me. I even tried to look for a PHP roadmap and see if proper method overloading will be introduced in the future but I could not find anything relevant.

A user with the name Noel has posted on DZone a little snippet of code that shows exactly how method overloading in PHP5 can be achieved.

Do you know of any intentions on including real method overloading in PHP6?

PHP/MySQL, Web Development , ,

Zend Studio 6.1: Wrong Way to Enhance a PHP IDE!

February 16th, 2009

In the past two weeks I have been doing some serious PHP development. Unlike .NET development where Microsoft’s Visual Studio is second to none, in PHP there was never a clear winner. So, I have decided to take the latest Zend Studio, version 6.1 on eclipse, for a spin.

As always, I give Zend, the company who created PHP a lot of respect. But with my usage of the Zend Studio IDE I have found more annoyances than features that helped me gain productivity. Here are some of the bad items I could not resist but rant about:

1. The entire solution now seems ‘gummy’. Where are the days when we can go through multiple PHP projects, and multiple PHP files in a few clicks and the IDE still feels ‘light’? Well, it doesn’t. In fact the more I use it the more this new IDE feels ‘yuck’.

2. My experience with the file/project manager on the left hand side was poor at best. If you have some scripts that update a file with fopen(), fwrite() – I had to force refresh on the parent folder of the updated file otherwise the IDE shows an error message when I try to open the updated file. What?

3. Auto complete is a little wierd. Ok, maybe a lot wierd. I really miss the auto complete that Zend Studio 5.5 used to have. While it is evident that the algorithms are trying their best to be smart, the whole user experience with the location of the auto complete windows, tabs vs enter keys to confirm the selection, and some inconsitencies in UI brings my frustration to uncharted levels. Dear Zend Develop team, can you please download and try Visual Studio and copy the ease of use? not hard to do.

4. Do I really need to create a new project, give it a name, choose a folder if all I want is a new PHP file? really? Do you ask your online users to fill out a 20 field form for a simple contact inquery? I DONT THINK SO.

5. Two files that I need my IDE to handle well: XML and SQL. All I ask for is to show me the text, dress it up with color, and handle nice any auto completion in a smart way. In this new versin of Zend Studio I was simply not able to open some XML files or the rigid editing of it made it impossible to work within the IDE, Notepad served nice in those cases. But this means failure to the IDE’s interface.

I do not know what made Zend decide on choosing a wrong turn with the latest version of Zend Studio (6.1). But it seems like the Zend team have decided to sacrifice a lot of functionality in order to cut on development efforts that the eclipse IDE supposedly provides. The only problem here is that eclipse’s features are weak and not good enough to be considered a good starting point for any PHP IDE who wishes to be claimed the best.

Time to try something new, the buzz seems to favor the latest PHP IDE by NuSphere: PHPEd.

PHP/MySQL, Web Development , , , ,

Understanding MySQL Query Caching Process

November 5th, 2008

These days, websites are expected to perform. No excuses. I also mentioned before that website performance is key for SEO. Well, one easy thing that can be done is turning on MySQL caching. Most servers ship with MySQL in its default configuration which has caching turned off. There are many resources out there if you search enough, however I have found a presentation by Baron Shcwartz: MySQL Query Cache which explains in detail advanced concepts of MySQL Caching. Here is the slide that summarizes the process of MySQL Query Caching:

LAMP: Linux Apache MySQL PHP, Performance Optimization, PHP/MySQL , , ,

ZenCart and Magento for eCommerce

September 22nd, 2008

Anyone who is involved with an online shopping cart and was considering open source solutions probably stumbled upon two major ecommerce providers: ZenCart and Magento Commerce. ZenCart is an evolving and older shopping cart with roots in osCommerce, while Magento Commerce is a newcomer to this category written from scratch on top of the new Zend Framework. Since we support both platforms, we often are asked to provide a basic comparison analysis for the business owners and this is what I will try to do in this article.


This is a great open source shopping cart that can power almost any size eCommerce sites. We have successfully used ZenCart for sites offering 20 products all the way up to tens of thausands of products and variations (which by the way is connected to a POS and kept up to date to the minute). Since its fork from osCommerce ZenCart has gone through extensive development and now offers much broader extendability and robust template system. Some of the underlying systems that make this shopping cart so robust are: template system, initialization system, object autoloaders, plugins a-la observer design patern, flexible and extendible configuration system, and more.

One of the biggest disadvantages for ZenCart is that all these great systems were built on top and in an after thought to an existing platform. Hence, there are many dependencies and the learning curve for professional grade customization and development is steep. For example, one of the tasks that current core developers are working on is to transform additional funcitons to object oriented design, in other words, they are still trying to get rid of the spagheti code left from the osCommerce days.

Nevertheless, ZenCart is a true workhorse that has proven itself many times and with hundreads of thausands of stores world wide. In fact, it has excellent support for multiple languages and multiple currencies stores.

At Activo, Inc. we have developed many modules to enhance various aspects of the store: front end, specialized templates, taxes by zipcode, easy search suggestion tool, even a real QuickBooks integration module and a real time Point of Sale (POS) integration with RunIt systems.

One more thing that ZenCart excels in when the right modules and the right setup is applied is SEO (Search Engine Optimization). Once setup correctly, ZenCart is one of the most SEO friendly stores out there. I have seen multiple times where a brand new ZenCart store with some SEO efforts generating more than $50,000 per month in sales (within 2-3 months of Go-Live).

ZenCart bottom line: Great solution if you want to see a solid and proven shopping cart with mostly standard features and you do not care about the type of technology that powers it. Currently, for best and fastest deployment ZenCart is second to none.


Magento is a brand new (about a year old as of writing this article) and it is now beginning to see community and developer adoption. Magento is written on top of PHP5 and Zend Framework. A bit about the framework: the new Zend Framework is sponsored by industry leaders such as IBM and Zend and is largely based on the MVC design patern. In a way, it is the answer to the .NET framework in the PHP world. There are similar frameworks and they may even be older and more mature, like Symphony or CakePHP. However, since the Zend Framework is backed by both IBM and Zend it is very likely that this framework will become the industry standard.

Magento was developed from scratch and in an object oriented manner on top of the new Zend Framework. Therefore, it is expected to have better extendibility options for developers and much better module/plugin management consules in the back-end however will probably come at the expense of instability in the short term. Magento’s templates out of the box look sharp and eye candy. Its creator definitely placed an emphasis on the way it’s admin panel feels & looks and the way its demo templates look & feel. Additionally, almost all aspects of the UI feels a lot more like Web 2.0 with many AJAX features and many time saving UI features.

One of the biggest downsides to Magento is its current speed since it lacks an effort in optimizing its DB and overall structure. Hence, it is relatively heavy and requires a bit of advanced know-how when installing and setting it up. It’s forums seem to be gaining traction with developers and many developers say that once you migrate a store to Magento you will never look back.

Magento bottom line: While it is definitely a matter of time until we see the real value, Magento does seem to have some advantages over any other open source eCommerce system. Merely the fact that it was developed from scratch recently means that a whole lot of best practices are thought of right of the bat instead of showing as an after thought (which we as developers have to deal with it). Nevertheless, Magento’s forums indicate that the product has yet to have reached maturity. If you are ok with somewhat unstable solution and looking for the absolute cutting edge shopping cart Magento is for you!

eCommerce, Magento, PHP/MySQL, Web Development, ZenCart , , , , , , , , , , ,

Looking Ahead: ZenCart ver 1.4

August 25th, 2008

The ZenCart developer team seems to be hard at work and preparing to deliver a new version of ZenCart: ver 1.4. The core developers posted a roadmap brief for version 1.4 back in September of 2007. Recently, additional entries have been posted in the forums describing in more detail the upcoming changes and signaling a new release is to be expected soon.

The currently described updates to ZenCart are done all around the DB, its architecture, and improving its performance. To summarise from the ZenCart forums:

New Database Driver Layer
Extremely light/flexible drivers make it easier to support other Database Types
Preliminary support for innodb and mysql transactions

Sql Caching system rewritten
Much easier to add new caching types
Preliminary Support for Memcache

Use of MPTT for category structure
Reduces number of queries needed to ‘describe’ the category structure
Improves user experience thru reduced page load times

Supporting Classes to reduce query load
Hugely reduces queries needed
Reuses queries using Cache to further improve performance

The roadmap for ZenCart ver 1.4 promises the following updates to the code (summarized):

  • Better usage of PHP 5.2 features. This also means 5.2 will be the new minimum requirement.
  • More Object Oriented code, less of the old osCommerce code.
  • Lots of DB improvements (some is described above, seems more is yet to come).
  • Category structure converted to MPTT format. MPTT stands for Modified Preorder Tree Traversal (explanation of MPTT).
  • Performance improvements for sites with lots of product attributes.
  • More function libraries converted to classes.
  • Duplicate components shared between admin and catalog.
  • Template system enhancements: less tables and more admin control.
  • Additional notifiers for the observer system.
  • Transaction support with InnoDB. Also mentioned as initial stage according to the recent posts of the updates that were done so far.
  • SwiftMailer instead of phpMailer.
  • Stock and SKU per product attribute.
  • Security enhancements.

Keep up the good work!

eCommerce, PHP/MySQL, Web Development, ZenCart , , , , , , , ,

ZenCart: Develop an Advanced Plugin Without Overwriting Core Files

May 26th, 2008

At Activo, Inc. we have a few products that integrate between ZenCart and other systems. Recently, we went through the exercise of rewriting our Activo ZenCart POS (RunIt) Integration plugin so it will not require overwriting any core files. It took some time to read and research the ZenCart’s best practices and to follow the documentation, however once we learned what is available and how to use it, converting the code was a breeze. Our previous version of the plugin included already some usage of the flexibility of ZenCart but to complete the abstraction we needed to use the initSystem and the Observer Class.

Making sure that your plugin does not override any other core files or doesn’t require tweaking any core files is important for several reasons. First, overriding core files prevents smooth upgrades – it doesn’t matter how small of a change you introduced once upgraded you will always have to reintroduce the change. Second, a plugin that does not override core files have better chances (95%+) that it will interact smoothly with other non-obtrusive plugins. Third, respecting the platform’s API extends the life of your plugin over several versions of the platform that it plugins to. The following four different methods or subsystems are available for writing efficient and non obtrusive plugins within ZenCart:

Template Override Mechanism

This is the most common way of modifying your own shopping cart and making it stand out from other ZenCart systems. I believe the template override system was introduced right after ZenCart was span off of osCommerce. While, the current templating system is not my favorite (Joomla CMS has a much better template system), it does introduce all the flexibility that one needs in order to generate a custom template in ZenCart. At Activo, we have developed several shopping carts that do not resemble a typical ZenCart site. Here is how:

  • look under the /includes/templates folder – you will find the two templates that ship with every ZenCart: ‘default_template’ and ‘classic’. To add your own template, create a new folder try to use related name to your site or store and make sure to follow linux web folder naming conventions as this folder will be used for every CSS, Image, or Javascript files on your site.
  • Add the description file to your newly created template folder. This file will allow some information to be displayed in the admin area of ZenCart under Admin > Tools > Templates.
  • You probably want to add a jpeg or gif screenshot image of your template front end, however this is optional. If you do, don’t forget to place it in /includes/templates/<Your Template Folder>/images and put the name of the file inside the ‘template_info.php’ file in the ‘$template_screenshot’ variable.
  • At this point you have a template that will display everything exactly as the default_template because each file that cannot be found under your newly created template folder, ZenCart will look for the same file under the ‘default_template’ folder. So, to custromize just copy one file at a time from the default_template folder and begin customizing.

Note there is a lot more to this templating system than the files that you can override under the custom template folder. This will require its own article altogether.

‘extra’ Files Automatic Inclusion

If you spend enough time looking around the ZenCart folder, you will find a few folders that start with the words ‘extra_’. Any PHP files under these will run through execution before any page loads. The main purpose of these folders however, is to include definitions or init values necessary for some modules or components that you install or that you are writing. Since these folders run before anything ‘interesting’ happens with ZenCart, it won’t help to run scripts here. Similarly you will find ‘extra_*’ folders under the /admin/includes and some additional all around the site with more specific purposes, here is the full list with a small description for each one:

  • /admin/includes/boxes/extra_boxes – Extra submenu items for anything but the first column of the admin menu.
  • /admin/includes/extra_configures – Configurations files for admin panel plugins.
  • /admin/includes/extra_datafiles – Data files and data file definitions for the admin panel plugins.
  • /admin/includes/functions/extra_functions – Additional function files. These functions will be declared globally in the admin panel and can be used form your plugins.
  • /includes/extra_cart_actions – Custom shopping cart actions. Special logic to the shopping cart.
  • /includes/extra_configures – Configuration files which will be included in the front end.
  • /includes/extra_datafiles – Data files and data file definitions for the front end plugins.
  • /includes/functions/extra_functions – Additional function files. These functions will be declared globally in the front end and can be used form your plugins.


The initSystem of ZenCart is an extendable system that allows programmers to define what happens on initialization while remaining within the ZenCart framework. In simple words: it lets a programmer set your plugin environment in any way, shape, or form without rewriting the ‘application_top.php’ file. From the wiki page directly:

The term initSystem, apart from being a tag used to group certain PHP files together in the new documentation, is meant to embrace all of those files that are automatically included/initialised before any ‘command’ scripts can be run.

Zen Cartâ„¢ uses a (non Object Oriented) page controller pattern to decide the scripts to run, based on HTTP_GET parameters. The most important of these is the ‘main_page’ HTTP_GET parameter. Depending on that parameter, a command script is then run. Each commmand script resides in a directory in /includes/modules/pages.

The essence of how to use it is well described in the wiki page. What’s nice here is that ZenCart’s own internals make use of this system and you can see it under the ‘init_includes’ folder. It is fairly easy to add your own init script files and extend ZenCart to fit your needs. Make sure to read all of the documentation on the wiki page since there are some easy-to-overlook pitfalls like file name conventions and the order of which things happen in this system.

Observer Class

The Observer Class system of ZenCart is a sophisticated way to avoid core hacks in common places. It is a design pattern that is being used a lot in operating systems, and GUI design. It introduces a notion of events. A set of global events is declared throughout the ZenCart system and you can define your own logic or set of tasks that can be invoked by attaching your class to a specific event or a set of events. The list of events is pretty vast with the latest version of ZenCart (ver 1.3.8a) and can be seen at the wiki page for this system.


The above four methods of customizing and extending ZenCart is all that a good programmer needs in order to develop a robust, scalable, modular, and secure shopping cart website. These systems do not exist in osCommerce or any other open source shopping cart systems out there, at least not at the same level of maturity.



eCommerce, PHP/MySQL, Web Development, ZenCart , , , , , , , , , ,