eKini: Web Developer Blog

PHP, MySQL, Javascript, MVC, Zend Framework, AJAX, jQuery

IBM makes PHP apps 3x faster with Xcache

February25

Makes sense. And you don’t need to recompile PHP and Apache to do it! Here is a snippet:

  PHP is a scripting language most often used to create Web applications. It’s easy to learn and produces visible results quickly. However, because PHP is interpreted, PHP code is parsed and translated to opcodes every time it executes. An opcode cache eliminates that rework, making PHP applications faster.

In a short time, PHP has become a popular programming language for Web applications. For the beginner, PHP is simple to install and easy to learn. For the more experienced developer, it (as of V5) offers robust object-oriented features. The community of PHP developers is enormous, and a significant number of open source and commercial libraries and tools extend the capabilities of the core language. PHP is favored by so many because it produces visible results rapidly.

Much like other scripting languages used for Web applications, including Perl, Python, and Ruby, PHP code is parsed, translated to opcodes (primitive instructions — akin to assembly language — that the PHP engine executes directly), and executed each and every time an HTTP request summons it. For negligible and low demand, your server executes this complex rendering process seemingly instantly. But as the number of pages served increases, interpretation — in essence, rework — can tax the system. In some cases, the “compilation” of your PHP code can far exceed the time required to execute the code. Hence, as demand grows, you can readily become a victim of your own success, as serving more dynamically interpreted, dynamically generated pages requires more and more resources.

If your site had an unlimited budget for processors and RAM, you’d likely never have to optimize your application stack (hardware, operating system, database, Web server, and PHP code) to keep your site responsive. However, because money is typically the scarcest of resources, tweaking for performance is inevitable. Tuning might mean adding memory to a starved system, modifying operating system parameters, hastening the Web or database server, rewriting code for efficiency, or some combination thereof. Each can contribute to gains.

Don’t burn cycles — Recycle

Yet another way to conserve CPU cycles is simply to reduce the amount of rework required to run your PHP application. Certainly, there is no need to translate the same PHP code each time. After your PHP code has been translated into opcodes, it can be saved and reused again and again — until the original code is modified. Indeed, caching — saving and reusing the intermediate PHP code, the opcodes — is the idea behind several PHP accelerators, including the open source Alternative PHP Cache (APC), Turck MMCache for PHP, XCache, eAccelerator, and the commercial Zend Platform. The latter three cache and optimize the byte code, providing for even greater speedups.

This month, let’s explore how to install, deploy, and configure XCache. XCache is a relative newcomer, but many sites are reporting good results with it. In addition, it is easy to build, install, and configure because it’s implemented as a PHP extension. Recompiling Apache and PHP isn’t required.

This article is based on XCache V1.2.0. It reliably supports PHP V4.3.11 to V4.4.4, PHP V5.1.x to V5.2.x, and early versions of PHP V6. (XCache doesn’t support PHP V5.0.x.) XCache works with mod_php and FastCGI, but not with the Common Gateway Interface (CGI) or the command-line PHP interpreter. The XCache source code builds on a variety of systems, including FreeBSD, Sun Solaris, Linux®, and (as shown here) on Mac OS X. XCache can be built on Microsoft® Windows®, as well, using the Cygwin UNIX® emulation environment or Visual C. You can build XCache for Cygwin or for native Win32. The latter target is compatible with the official Win32 release of PHP.

Click Here for the entire article.

posted under Uncategorized | No Comments »

Very Simple PHP & MySQL Pagination

February20

Here is a very simple tutorial to implement pagination using PHP and MySQL. Although this is not a fully working code, hopefully, the information provided here will be enough for most intermediate PHP programmers.

  1.  
  2. $max = 10;
  3. $page = $_GET[‘page’];
  4. if (!$page) {
  5.     $page=1;
  6. }
  7.  
  8. $sql_query = ‘SELECT * FROM table t WHERE t.fieldA = "Active" LIMIT ‘.$limits.‘,’.$max.;
  9. //Code to execute the $sql_query here
  10.  
  11. $totalresult = ‘SELECT * FROM table t WHERE t.fieldA = "Active"’;
  12. //Code to execute the $totalresult query
  13. //then assign the total number of rows to $total variable
  14.  
  15. $totalpages = ceil($total / $max); //remember, we assigned $total the total number of results from the $totalresult query?

Now for the HTML part of your code you can use $totalpages to do a for-loop to generate the Page Numbers then assign links to $_GET[’page’] using the counter from the for-loop.
For example:

  1.  
  2. <a href="http://locahost/pagination.php?page=’1′">Page 1</a>
  3. <a href="http://locahost/pagination.php?page=’2′">Page 2</a>
  4. <a href="http://locahost/pagination.php?page=’3′">Page 3</a>

The HTML code above can be generated using the PHP code below:

  1.  
  2. for ($i=1; $i < $totalpages; $i++) {
  3.     echo "<a href="http://locahost/pagination.php?page=%22.$i.%22">".$i."</a>";
  4. }
posted under Uncategorized | 1 Comment »

Interesting PHP Framework: Stubbles

February19

This one certainly caught my attention. I have been browsing around for a good MVC framework, and I am playing around with Code Igniter as of the moment. But Stubbles I think definitely deserves some attention. It is fairly new to the whole framework community for PHP 5.x but you should give it a look sometime…

Stubbles is completely different from the approach CakePHP takes. It will not enable you to build CRUD applications in mere minutes. You will have to write a lot more code on your own.

Stubbles is just beginning to grow, so it currently does not offer you all the functionality, that the frameworks you mentioned, offer.

But as we offer the extended reflection support and some nice features when it comes to creating XML, I can still recommend, that you combine the powers of several frameworks. That’s the same approach we will be taking, when using Stubbles in our own projects. We do not aim at replacing these frameworks.

As soon as we finished the basic MVC architecture, we will write some tutorials, to explain how Stubbles can be used to build web applications (which will be mainly built with XSLT).

posted under Uncategorized | No Comments »

A Definitive Guide to Arrays in PHP

February18

Here is a long guide to arrays in PHP.

Good Day!

Here is yet another article of Fast PHP Articles Series. Today we are going to discuss ARRAYS. We will learn its syntax, its different types, the different built-in Array functions that help to perform different tasks related to Arrays quickly and different practical examples explaining the use of Arrays in PHP.

By the end of this article you should be able to ,

- Define Arrays :) - Use different types of Arrays
- Use different Built-in functions related to Arrays e.g list(), each(), var_dump, print_r, var_export()

- Write basic as well as complex php code using Arrays.
- Working with multidimensional arrays
- Understanding Foreach loop with the help of different examples

posted under Uncategorized | No Comments »

PHP on the rise

February10

PHP as a programming language is again on the rise. TIOBE Software has used search engines like Google and Yahoo! to calculate the ratings. Keep in mind that this is not about the best programming language and so on so fourth. PHP has risen back to number 4 replacing Visual Basic. It is now next to all-around and powerful languages like Java, C and C++.

posted under General | No Comments »

Unable to Claim My Blog in Technorati

February8

I have been unable to claim my blog on Technorati. I am not sure whether it is my server’s fault or Technorati’s. But everytime I try to claim this blog, I get this error:

There was a problem claiming your blog. Please try again in a few minutes. You can also go to Technorati Help for help claiming your blog.

I have contacted Technorati and I am given some kind of auto-reply. Hope this gets fixed soon. Has anyone encountered this problem with Technorati?

posted under Uncategorized | No Comments »

Adding and Removing a List Item to a List Using Javascript dynamically

February7

There are a couple of ways to do this but I find this one the simplest.

First, you create your HTML Code such as below:

  1.  
  2. <strong>Below is a list item:</strong>
  3. <a href="#" onclick="addListItem(’the_list’); return false;">add item</a>
  4. <input id="list_counter" value="2" type="hidden" />
  5. <ol id="the_list">
  6. <li id="listItem_0">This is a list item.</li>
  7. <li id="listItem_1">This is another list item.</li>
  8. <li id="listItem_2">Yet another list item.</li>
  9. </ol>
  10.  

The ID for the UL tag and LI tags will be used by the Javascript code below:

  1.  
  2. function addListItem(listId) {
  3.      var listOfItems = document.getElementById(listId); //get the list ID
  4.      var listCounter = document.getElementById(‘listCounter’); //get the hidden list counter
  5.      var listCounter_value = listCounter.value; //get the value of the hidden list counter
  6.      var new_li = listOfItems.createElement(‘li’); //create a new LI element
  7.      new_li.setAttribute(‘id’,‘listItem_’+listCounter_value); //make the ID for the new element
  8.      new_li.innerHTML = ‘<em>This is an italicized list item.</em><a href="#" onclick="removeItem(listItem_’+listCounter_value+‘)">remove this item</a>’; //the stuff that is inside the LI
  9.      listOfItems.appendChild(new_li); //add the new LI
  10.      listCounter.value = listCounter_value++; //update the value of the list counter
  11. }
  12.  
  13. function removeItem(listItem) {
  14.      var listOfItems = document.getElementById(‘the_list’); //get the list
  15.      var targetListItem = document.getElementById(listItem); //the specific list item, that’s why we placed created an attribute for it
  16.      listOfItems.removeChild(targetListItem); //this removes the list item
  17. }
posted under General | No Comments »

MySQL native driver for PHP6 (mysqlnd)

February7

That’s right, you heard me right: PHP6. Since PHP5 had very big improvements from PHP4, especially on the OOP side, I am already excited with the new stuff that will come with PHP6. And with this new addition (the mysqlnd and with development as early as now), the marraige between PHP and MySQL will even be stronger. The mysqlnd will be a superior alternative for libmysql. There will be backward compatibility since libmysql will not be removed.

Advantages of mysqlnd

The new development is licensed under the terms of the PHP license to solve any license issues.

During the early stage of the development we will offer it from MySQL. As soon as mysqlnd is feature complete and production ready we will move it to the PHP project CVS repository on http://cvs.php.net.

On the C-level mysqlnd uses many of the proven and stable PHP internal functions. All the code of the new driver is contained in the ext/mysqli source directory. There is no need to link any external libraries. Thus you neither need to install the MySQL client library to compile PHP with ext/mysqli support nor do you need to take care of versions. Compiling has been made easier.

The performance of some functions has been improved. We have measured considerable performance improvements, for example when fetching buffered result sets.

Features and Limitations

This first, alpha release is not feature complete. From the API additions discussed with Community members in November 2006 during the Frankfurt PHP conference, we managed implement a first version of:

  • improved persistent connections
  • mysqli_fetch_all()
  • a first performance statistics call: mysqli_get_cache_stats()

More additions will follow.

Unfortunately the first alpha release does not include Prepared Statement Support.

You can read more here.

posted under Uncategorized | No Comments »

Adium X 1.0 just released

February6

adium.pngThe annoying little green duck is now on its 1.o release. For those of you who are not familiar with Adium, it is a free Instant Messaging client for Mac OS that can connect to almost all the networks like Gtalk, Yahoo Messenger, MSN Messenger, ICQ, AOL Instant Messenger and many more. You could even connect to IRC Servers like efnet and undernet.

posted under Uncategorized | No Comments »

PHP.net updates the Manual

February5

PHP.net has probably the best manual in world. All manuals should be like PHP.net. The guys over there updated the Manual. My new favorite feature would have to be that the manual pages can now have images. It would be something fresh for the eyes because since the beginning of time, all I have been seeing on the manual have been all text. Not that I’m not satisfied; like I said, it is the best manual in teh freakin’ 3nt1RE world!  I have yet to see a page with an image though. Could someone give me a link?

  • an improved, XSL-based build system that will deliver compiled manuals to mirrors in a more timely manner (goodbye dsssl)
  • manual pages can now contain images (see imagearc() for an example)
  • updated function version information and capture system (fewer “no version information, might be only in CVS” messages)
posted under Uncategorized | No Comments »
« Older Entries