PHP, MySQL, JavaScript, Windows 7, Linux
Posts tagged PHP
Using memcached with WordPress
Dec 20th
Today, I decided to implement a popular distributed caching system called memcached. Memcached allows PHP objects and variables to be stored in memory, which when used properly, can decrease page load time and server load. Memcached can also work as a central cache for a cluster of servers. File-based caching systems work by generating static files, and storing them in a local directory to be served in place of the dynamic content. This can reduce the number of database queries, and help avoid having to process the script with each new request; however, there is a downside. Read the rest of this entry »
PHP 5.3.1 is finally here!
Nov 19th
After four release candidates, we finally have a stable PHP 5.3.1 release. For those already running PHP 5.3.0, there’s not much that is different, but there are some improvements. For others, it means there will probably be PHP 5.3 support in cPanel/WHM via EasyApache very soon.
In PHP 5.3.1, the max_file_uploads directive was introduced into php.ini to help prevent DOS (denial of service) attacks via file exhaustion. max_file_uploads is set at 20 by default. There were also several other security issues patches, and many bugs fixed in this release. Links containing additional details are below:
Adding default database table prefixes in Zend Framework 1.9.x
Sep 8th
Recently, I began working with Zend Framework 1.9.2 to restructure one of my web sites. I learned how to create an extension of the Zend_Db_Table_Abstract from a great “Getting Started” tutorial, but I found myself rewriting the table prefix with each and every new table. Below I explain one solution to this problem, but I am new to Zend Framework, so please feel free to recommend a better, more integrated way of doing this, if you know of anything.
Step 1: application.ini
Place the following code in your /application/configs/application.ini file:
[production] table_prefix = "webjawns_"
Step 2: TPC_DB_Table_Abstract class
Create a new class in the library directory. For this example, we’ll use TPC_DB_Table_Abstract as the name, which will be stored in /library/TPC/DB/Table/Abstract.php.
<?php
class TPC_DB_Table_Abstract extends Zend_Db_Table_Abstract {
protected function _setupTableName() {
global $application;
parent::_setupTableName();
$prefix = $application->getOption('table_prefix');
$this->_name = $prefix . $this->_name;
}
}
Step 3: /application/Bootstrap.php
After that, you’ll want to make sure that the new Abstract.php file is referenced in your /application/Bootstrap.php file.
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader( array(
'namespace' => '',
'basePath' => APPLICATION_PATH ) );
$moduleLoader->addResourceType('', '../library/TPC', 'TPC');
return $moduleLoader;
}
Step 4: /application/models/DbTable/NewTable.php
To use the table prefix, we will basically be substituting Zend_Db_Table_Abstract with TPC_DB_Table_Abstract. See the example below:
class Model_DbTable_NewTable extends TPC_DB_Table_Abstract {
// Database name will be $prefix + $_name
protected $_name = 'newtable';
}
This is just one way to create default table prefixes for each of your tables. I’m sure this isn’t the only way, and there may even be better, easier ways to do this. As an added bonus, we use the TPC_DB_Table_Abstract class to extend the Zend database functionality even further. If anyone else has any ideas about how to use default table prefixes (other than using a constant), please feel free to share them so we can all benefit.
MySQL database class using Singleton design pattern
Aug 30th
(Note: The following is a revised tutorial I wrote earlier this year, transferred from one of my old web sites.)
Using the Singleton design pattern is a simple way to limit the number of class instances to one, helps keep database connections organized, and can also save memory. The PHP code below is a basic example on how to use the Singleton pattern to create a database class. This class can be used to manage a database connection throughout PHP script execution. While this is a basic example, many improvements have been made over the original version. If this is well received, we will be happy to add additional functionality. Click read more to view the class, and learn about the functionality of each part. Read the rest of this entry »
Top 3 PHP IDEs
Aug 28th
What can I say about our beloved IDEs? To those just learning, this may just seem like another meaningless acronym in a world already filled with pointless acronyms; however, this will save your life … literally! So, what is an IDE?
IDE stands for Integrated Development Environment. IDEs allow you to perform a multitude of tasks from one place. Example uses of an IDE include editing code, debugging an application, and updating SVN. IDEs don’t have to include all of these features, and they aren’t limited to just these features.
Below I’ve compiled my top three PHP IDEs:
1. Eclipse PDT (Free)
Eclipse is extremely powerful and supports a multitude of programming languages, most notably Java. Eclipse PDT includes built-in support for JavaScript, and comes complete with code assist/completion, syntax highlighting, SVN and CVS support via Subclipse, project management features, and more. The all-in-one package also comes with a PHP debugger. The downside is that it can be kind of slow at times if you are on an older PC.
2. Crimson Editor (Free)
Alright, so Crimson Editor is more of a “text editor” than anything else; however, it has proven to be quite useful regardless. Though Crimson Editor hasn’t been actively worked on since 2008, when it was renamed Emerald Editor by another team, it is great for working on dual screens. I often find myself using Crimson Editor to copy code from one place to another (i.e. Eclipse PDT on screen A, Crimson Editor on screen B). Crimson Editor also comes equipped with syntax highlighting for many languages, word wrap, project settings, and built-in FTP. CE is great because it takes up next to nothing as far as RAM and CPU, but it is not as robust as NetBeans or Eclipse PDT.
3. NetBeans (Free)
NetBeans is similar to Eclipse PDT, but is a little less robust in my opinion. It does, however, offer version control functionality and database support right out of the box, as well as the other key features of any other IDE. It seems to be a little faster than Eclipse, and has gained traction in the community. I don’t really use NetBeans too often, but if Eclipse went away, I would start eating NetBeans.
There are many more great IDEs out there, but these have made quite the impression on me and some of my friends. It really comes down to personal preference, and what you are trying to do. They all revolve around the same basic principles, and have similar features. Try each one out, and find out what works best for you.
I encourage everyone to comment and let us know which IDE you use and why you use it.
a2i48m6tnu



