PHP Programmers Club
Contact information, map and directions, contact form, opening hours, services, ratings, photos, videos and announcements from PHP Programmers Club, Dance club & nightclub, 136 Everlasting Street, Bulihan, Malolos.
I usually receive requests from programmers for help in some coding difficulties. I suggests that those with problems post it here so that the community could give comments and solutions.
For those of you trying to create a pie chart in PHP and SQLITE, there are several llbraries available. Try to google or search SourceForge. or Github.
09/03/2016
PHP Class Scripts, Tutorials, Jobs, Jobs, Book reviews, User groups, Forums - PHP Classes Free PHP Classes, PHP Tutorials, Download PHP Scripts, PHP articles, PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials
Programming Environment
What OS?
HTML and PHP are OS (operating system) independent. Meaning, it runs on Windows, Mac OSX, Solaris, Unix and Linux. Theoretically, code written on windows will run on Linux and vice versa. Many programmers use Windows in their desktops for programming.
I have been using Windows for development since my Visual Basic days. So when I started learning HTML and subsequently, PHP, it was natural for me to continue using Windows. Although at that time, PHP was awkward and unstable under Windows. Today, the newer PHP versions are fast, stable with reliable and extensive development tools under Windows. For our purpose, we will use Windows as our development operating system.
HTML, CSS and Javascript
HTML or ‘HyperText Markup Language’ is the standard script used to create browser documents. HTML is composed of text enclosed in angle brackets called tags. Tags usually comes in pairs like and , although some tags are unpaired, for example .
The purpose of a web browser is to read HTML files and display them. The browser uses the HTML tags to display the content of the visible page. HTML tags form the structure of all websites. It allows pictures to be displayed and can be used to input information through HTML forms.
It can embed Javascript which affects the behavior of web pages. HTML also interacts with Cascading Style Sheets (CSS) to define the color, look and layout of text and other objects.
Apache, PHP and MySQL
PHP is used by 81.8% of all the websites whose server-side programming language is known. Roughly, 244M sites uses PHP as one of their scripting languages. HTML on the other hand is universal. Where there is a browser, HTML runs on it.
The popularity of PHP can be ascribed to several factors: It is powerful, it is easy to use and it is free. PHP has the enviable position of being free, server side, and a scripting language that is regularly updated, robust, and scalable.
PHP is typically used with HTML and a web server like Apache. Requests for web files are received by the Web server. Scripts inside PHP tags are handled by the PHP interpreter and converted to HTML. The results obtained after ex*****on are returned to the Web server, which takes care of transmitting them to the client browser in HTML format.
Surprisingly, PHP itself, performs like a regular programming language. It can perform calculations, process database request, create animations and read/write files. Practically, anything you can do with a regular programming language, you can do with PHP.
In addition to Apache, PHP also needs a database. Although PHP recognizes many popular databases, I use MySQL; Not only because it is free and popular but because updates and patches are frequent. Experience proved to me that it can handle tasks anywhere from simple to enterprise database clustering. In addition to MySQL, we also need phpMyAdmin software to manage MySQL and its data.
Web Server
What is XAMPP?
In order to begin web development, you need to set up a proper development environment. First you need a working web server like Apache. Then you need to install copies of PHP and MySQL. Then you need to tweaked their configuration to make sure they operate together optimally in development mode.
I used to install Apache, MySQL and PHP individually and manually; and every time, I encounter problems.
Detailed instructions on how to set up this development environment on each platform are available in the online manual, at http://www.php.net/manual/en/installation.php – or, you can just download a copy of XAMPP. Thank goodness, a life saver ,in the form of XAMPP, appeared.
XAMPP is one of the most popular PHP development environments today. XAMPP is a software package for the installation of Apache HTTPD web server and other related software. The package includes MySQL, PHP, Perl, phpMyAdmin, and other utilities integrated with Apache HTTPD. There are different variation for Linux, Solaris, Windows, and Mac OS X.
Features
The XAMPP package contains the following:
Servers:
Apache HTTPD : The world's most popular web server today.
Apache Tomcat : is an open-source web server and a Java HTTP web server environment for Java code.
FileZilla FTP Server : A file transfer utility server over the web.
Mercury Mail Transport System : An email server
Programming Languages:
PHP : The most popular programming language in the internet today.
mod_perl : An optional module of the Apache HTTP server. It installs a Perl interpreter in Apache server.
Databases:
MySQL : The most dominant database in the internet.
SQLite : is a popular choice as embedded database.
phpMyAdmin : A MySQL database management utility software.
Tools & Libraries:
OpenSSL : a free set of encryption tools for the code used on the Internet.
Freetype : a software development library, provides support for other font-related operations.
Webalizer : An application that generates web analysis, from log files.
eAccelerator : eAccelerator optimizes the compiled bytecode and caches this to shared memory or disk or both.
Mcrypt : mcrypt is a file encryption tool
fake sendmail for windows : An application that emulates sendmail.
FPDF Class : A PHP library for creating and editing PDFs (Adobe).
Installing XAMPP
______________________
Note : XAMPP can be downloaded free at
http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/ _
______________________
XAMPP for Windows is in three different variations:
1) Windows Installer: Installs like any windows application.
2) Zip: XAMPP in Zip archive.
3) 7zip: For slow connection, as 7zip archive.
______________________
Caution ! : When you extract the files,
there can be false-positives virus warnings.
_____________________
We will choose Zip, and download the zip file. Unzip the zip archive into the root of C:\ drive. XAMPP will extract to the default subdirectory C:\xampp.
If you choose a subdirectory other than the root directory of C: as target, you must run setup_xampp.bat and choose absolute path.
If you are installing XAMPP on a usb drive, do not run setup_xampp.bat. All usb drives cannot have a permanent drive letter. However, if you still run setup, choose relative paths. You can switch from absolute to relative paths at any time with setup_xampp.bat script.
Once you extract the zipped file, XAMPP is ready to use. No more installation, no fiddling with the registry, almost no configuration setup. That is the beauty of the zip file installation.
Part of the installation is the file xampp-control.exe, the control panel of XAMPP to start/stop Apache, MySQL, FileZilla & Mercury. For convenience, a shortcut at the desktop should be created.
To put a shortcut at the desktop:
1) Use My Computer or Windows Explorer to locate the file xampp-control.exe to which you want to create a shortcut. It can be found at C:\xampp.
2) Right-click the file, and then click Create Shortcut from the menu.
3) Drag the new shortcut to an open area on the desktop.
If you had installation problems, where XAMPP Control Center could not start Apache, it probably is in conflict with another application using the same port 80, such as a firewall or Skype.
To fix this, change the port of Apache to 8080. Open your httpd.conf file in the C:\xampp\apache\conf directory and :
Locate the following lines:
Listen 80
Change this line to:
Listen 8080
Then locate
ServerName localhost:80
And change to
ServerName localhost:8080
If you are experiencing problems, the Apache Foundation has provided a Frequently Asked Questions document about issues usually encountered during use and installation. You can view the FAQ by going to http://wiki.apache.org/httpd/FAQ.
XAMPP is now ready to serve you. You can use the XAMPP Control Panel to start/stop all servers and also install/uninstall services.
Now that we have installed XAMPP, our next move is to configure XAMPP for development work. Of course the default configuration of Apache, PHP AND MySQL is adequate enough for many kinds of work. But what we need is an environment suited specifically for what programmers do.
Apache Configuration
For Apache, the configuration is good enough for development purposes. We do not want to diverge too much from the default setup. However, if your production server has a different setup than the default one, those production configuration, if relevant, must be reflected on the development server.
PHP Configuration
For PHP, the configuration file, named php.ini, is responsible for many of the aspects of its behaviour. PHP comes packaged with two INI files. One is php.ini-production, and the other one is php.ini-development.
php.ini-production contains settings which emphasize security, performance and best practices. We recommend this ini file in production and testing environments.
php.ini-development is very similar to the production ini file. It is however, very strict when it comes to errors. We will use this ini file for our environment. This ini file must not be used in production as errors shown to application users can inadvertently leak confidential information.
To use the php.ini-development file, rename the file php.ini. Then start PHP
MySQL Configuration
However, for MySQL, it is a different story. Database operation requires different setup from production environment or from a development one. There are three areas to consider; memory handling, error trapping, slow query logging.
As a default, MySQL is configured for systems with memory less than 64MB. This is not enough for production or even for development. It places a constraint that slows down data retrieval.
For production, memory can be configured up to 80% of the physical memory of the server, especially if it is a dedicated one. For development purposes, I would recommend only 50% of the physical memory since development is usually done on desktop PCs with multitasking demand. Programmers normally code with music playing in the computer. Sometimes it is necessary to be connected to the internet at the same time. Just remember that MySQL configuration is different in development than in production.
Configuration options for MySQL can be found in a text file named my.ini located at C:\xampp\mysql\bin This is read by MySQL during start up. There are several options to be changed to optimize memory handing of MySQL. It is necessary that the configuration change be done correctly, otherwise the database would crash.
There are several options to be set for log files. One is the error log file and the other is the slow query log file. Also we should include in the slow query log queries without index, The options are:
log_error = mysql_error.log
slow_query_log = 1
log_queries_not_using_indexes = 1
slow_query_log_file = mysql_slow.log
To avoid the time, complexity, and risk of customizing a my.ini configuration manually, I employ the online services of Percona to generate a configuration. Just go to https://tools.percona.com/wizard and follow the instructions. Simply copy and paste the results of the Percona Configuration Wizard for MySQL into your my.ini file.
What is a Program Editor?
Browsers requesting a web page from a server expect an HTML page in return. Any PHP in the page are processed in the server and converted to HTML. When the HTML page is complete, it is sent back to the requesting browser.
When I begin coding a page, the initial thing that I do is to compose the HTML part. Why HTML first? I want to see how the page will look and make sure the JavaScript and CSS components works and bug-less. This is where the colors are selected and the layout decided. The pages are tested on its look and behavior with different displays, like PC monitor, tablets and cell phones.
With the proliferation of modern gadgets and the advancement on HTML, CSS and JavaScript, PHP programmers spends a lot of time on HTML programming; finalizing the look-and-feel of the pages. That’s why we need an editor capable of creating HTML pages on the fly.
A program editor is a computer program for creating and editing program codes. Ideally, it must provide convenience, like syntax highlighting, wizards, tool tips, auto-completion, templates, toolbars, debugging and auto-formatting. Keyboard shortcuts and even drag-and-drop feature must be available to quickly insert common HTML elements and structures. WYSIWYG or what-you-see-is-what-you-get is a special category of editors desirable especially for an HTML editor.
Ideally, the editor should also work with related technologies such as CSS, JavaScript and PHP; although most HTML editors provides only basic features for these.
There are many HTML editors available for Windows today. Ranging from the simple Notepad to complex ones like Dreamweaver of Adobe.
WYSIWYG - a few HTML editors provide a graphical editing interface which visually shows how the page will be displayed in a web browser. Because using a WYSIWYG editor may not require any HTML knowledge, they are often easier for an average computer user to get started with. These editors may be stand-alone programs, such as Adobe Dreamweaver, Kompozer, Quanta Plus and Expression Web.
Microsoft Expression Web 4
For me, I choose Microsoft’s Expression Web 4. Simply because it is free and it has a lot of features that makes it easier to edit HTML, CSS, JavaScript and PHP programs. Some of these features are:
Syntax highlighting - A feature of programming editors that displays text, especially source code, in different colors and fonts with various meanings.
Highlight invalid code - Expression Web can highlight invalid HTML and CSS code with a red, wavy underline in the Code view of a page.
Wizards - A sequence of dialog boxes that lead the user through a series of well-defined steps. Data input that are complex, lengthy or unfamiliar to users are best served using a wizard to complete the process. Wizards usually use simple but precise terms in interacting with the users.
Expression Web uses a wizard to import external web sites or files. It uses wizards in automating a lot of tasks. In fact, by using wizards, one can program with minimal code typing.
Tool Tip - A message that appears when a mouse pointer is positioned over a web item (icon, image, hyperlink, or other elements) in a HTML page. The user hovers the pointer over the item, without clicking it, and a tool tip may appear—a small "text box" with information about the item.
Auto-Completion - A feature, provided by many source code editors, where the editor predicts a word or phrase that the user wants to type in without the user actually typing it completely. It involves the user typing one or several characters and the editor shows a pop-up list of possible completions for the current initial input to allow the user to choose the right one.
When writing HTML, PHP, CSS or Javascript, the auto-completion feature suggests elements as soon as you type an open bracket, reveals suitable attributes or events if you enter a space, helpfully inserts quotes for you when you use an equals sign, and inserts the right closing tag when you close your brackets.
Templates - A pre-developed page layout used to make new pages with a similar design, pattern, or style. a master page used to produce web pages.
Expression Web 4 uses Dynamic Web Template (DWT), an HTML-based master copy of a web page that you can create to contain settings, formatting, and page elements such as text, graphics, page layout, styles, and content of a page. When you attach a dynamic template to the pages in a site, the pages inherits the style and content of the template.
Toolbars - A toolbar is a row or column of selectable images that give the user a visible prompt and a simple way to choose specific editor action or function, such as saving a page or printing a document.
The Code View toolbar of Expression Web provides users with a convenient way to access many features that make it easy editing the source code of a web page. The Code View toolbar groups commonly-used commands from the code view in one row of icons.
Expression Web even lets you create your own toolbars through the Custom Toolbars and arrange commands and icons to suit your preference.
Auto-Formatting - A software feature found in HTML Editors such as Microsoft Expression Web 4 that automatically changes the formatting or appearance of text. For example, if a user types "1st", Auto-Format would change this to "1st."
Keyboard Shortcuts - A combination of keys that, when pressed simultaneously, perform some task that ordinarily requires use of a mouse or other input device and may take longer to do.
A few sample keyboard shortcuts of Expression Web are:
Save a web page CTRL+S
Print a web page CTRL+P
Quit ALT+F4
Replace text CTRL+H
Check spelling F7
Insert start tag CTRL+COMMA
Insert end tag CTRL+PERIOD
Cut selected text CTRL+X
Drag-and-Drop - Text, pictures, and other content is added to a site by dragging them from windows explorer and then dropping them to a page in design view of Expression Web 4.
Hover your mouse over an item in Windows Explorer. Then left-click on the item with your mouse and drag it to the page in design view of Expression Web 4. Once you've found where you'd like to place it, release the left button on the mouse and the element will be dropped. Now you can edit this element to add your content.
Features and Capabilities
Microsoft Expression Web 4 gives you the tools you need to produce professional Web sites:
• Support for today’s Web standards,
• Quality CSS design capabilities, and
• Visual debugging features.
• Support for JavaScript, CSS and PHP
First and foremost, before installing this application, the system requirements need to be thoroughly checked, as software complexity comes with a price, both figuratively and literally. The system requirements for Expression Web 4 are:
1) Windows 7/8/Vista/XP
2) PC with 1 GHz or faster processor
3) 1 GB of RAM or more
4) 2 GB or more of available hard-disk space
5) NET Framework 4.0
6) Silverlight 4.0
7) Support for Microsoft DirectX® 9.0 graphics
8) 1024 x 768 or higher resolution monitor with 24-bit color
9) Internet functionality requires Internet access
Beginners might have a hard time initially learning to use this product, but in the end they will be pleased with the power and utility of the editor. At the same time, old timers will find a lot of tools that will allow them to fine-tune their applications.
Installing Microsoft Expression Web 4
Before you can install Expression Web 4, you will need to have .NET Framework 4.0 and Silverlight 4.0 installed. You may want to download and install them first as your computer will need a restart after installation.
To download Expression Web 4 go to http://www.microsoft.com/en-ph/download/details.aspx?id=36179. After downloading Expression Web 4, click on the installation file Web_Trial_en.exe and follow the instructions.
Step 1: Once you have downloaded the program file, double click on the file Web_Trial_en.exe to start the installation. You will receive the normal User Account Control warning box. Click Yes. Then you will see the install process start.
Step 2: The second screen will display the license agreement and you will be asked if you accept it or not. Accept the license agreement.
Step 3: Choose whether you wish to join the Customer Experience Improvement Program.
Step 4: Select which of the programs you wish to install.
Step 5: Once the entire program is installed, you will see the finish setup screen. Click Finish.
_________________________
Caution! : If you have problems installing Expression Web,
go to http://msdn.microsoft.com/en-us/expression
_________________________
Data Generator
http://www.mockaroo.com/
Why is test data needed?
If you are a programmer, developing a website, you will want to test it under realistic conditions. If you are entering test data manually one record at a time, you're never going to build up the volume of data that will approximate live data in a few days in production.
Likewise, the data you enter will be influenced by your own usage preference, lacking variety and leaving important bugs undetected.
Live data is varied and will contain characters that may not sit well with your program; such as ASCII codes, or unprintable characters. Your test data should mirror live data in volume and variety. It should also include unwanted data to identify the point of failure of your program to validate and catch the unwanted data.
This is also vital in identifying erroneous and/or slow queries; the perennial problem of large databases and complex queries. It is very hard to identify errors in queries with insufficient number of records in data; more so slow queries.
What is Mockaroo?
Mockaroo is a website that offers as a service, test data generation. Mockaroo allows you to generate online, large amounts of randomly generated test data based on your own parameters. You can then save it in your PC then load directly into your own database in SQL or CSV formats using phpMyAdmin
_____________________
NOTE : To generate your own test data,
go to http://www.mockaroo.com/
_____________________
Dummy Text Generator
In programming a website, you usually need a sample text in place of an article or a blog post. In practice you will use Lorem Ipsum in place of an English text. In printing press parlance, Lorem Ipsum is a text placeholder in Latin commonly used to demonstrate the textual elements of a document or visual presentation. By replacing the English content with scrambled Latin, it removes the distraction of English words and let viewers focus on typographical attributes such as font, spacing, color and size.
The lorem ipsum text is a part of De finibus bonorum et malorum, by Cicero, with words changed to make it gibberish Latin. Originally, the Lorem Ipsum text has been used in typesetting. Then it was popularized in computers by Aldus Corporation, through its desktop publishing software, Pagemaker, which used it in templates.
There are several ways one can generate Lorem Ipsum text.
1)Code Snippet, 2)Online 3)Word Document
Expression Web 4 Code Snippet
The Lorem Ipsum text can be made a part of Expression Web 4. You can include the text in your Code Snippet list and have it readily available anytime you need a Lorem Ipsum. To include the Lorem Ipsum text in your Expression Web 4 Code Snippet, do the following:
Step 1 - Copy and save the following code snippet:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam consectetur justo consequat mauris mollis eleifend. Donec lacinia lorem et nulla faucibus, vitae interdum lectus eleifend. Suspendisse purus dolor, mattis vitae velit a, ultricies suscipit massa. Nam congue fermentum justo, vitae rhoncus erat bibendum non. Ut lacinia aliquam elit, ut molestie orci posuere et. Donec luctus ante quis sapien scelerisque viverra. Etiam laoreet feugiat sem, quis mollis nibh lacinia ac. Cras eget euismod massa, quis ultricies erat. Duis lacinia sit amet est consectetur facilisis. Nam non odio at mauris elementum tristique et id ante. Integer ac mauris felis. Sed semper accumsan ante in scelerisque.]]>
Step 2 - Name the file Lorem.ews, then
Step 3 - Type %appdata% in the URL address of your Windows Explorer. This is to access the subdirectory application data which is protected.
Step 4 - copy the file Lorem.ews to the following :
C:\Users\[username]\AppData\Roaming\Microsoft\Expression\Web 4\mySnippets\
Step 5 - In EW4, open your web page, go to the Code view and put your cursor where you want the lorem ipsum text to appear, and press CTRL + ENTER. A list of code snippets including Lorem should appear. Double click the code snippet Lorem and that’s it; you have a Lorem text.
Generate Lorem Ipsum Online
Step 1 - In your browser, go to the Lorem site, http://www.lipsum.com/
Step 2 - At the right lower corner is a form for generating Lorem Ipsum (see figure 1). Select the type of output you want. Default is paragraphs. Input the number of paragraphs; default is 5.
Step 3 - Click Generate Lorem Ipsum button.
Step 4 - The Lorem Ipsum text will appear below the form. Copy and paste on your web page.
Microsoft Word@ Function
To generate Lorem Ipsum text in Word 2007 or Word 2010, type =lorem() in the document where you want the text to appear, and then press ENTER
You can specify how many paragraphs and lines of Lorem Ipsum will be generated by adding paramete
rs The =lorem() function has the following syntax: lorem(p,l) where ,p is the number of paragraphs, and l is the number of lines that you want to appear in each paragraph
The parameters are optional. If you leave the parameters blank, the default number of paragraphs is three, and the default number of lines per paragraph is also three.
Database Manager
http://www.phpMyAdmin.net/
Introducing phpMyAdmin
As a programmer, you need a database manager for MySQL . There are several software available out there. But the most popular is phpMyAdmin. And it is free. And as a bonus, it is wriltten in PHP, making it easy to debug in case of errors. Its purpose is to handle the administration of MySQL.
phpMyAdmin manages MySQL with a wide range of operations. It
is commonly used in adding, deleting, editing, searching database, tables, columns, indexes, users and permissions. Also a frequently used operation is the ability to directly execute any SQL statement.
phpMyAdmin is released by http://www.phpMyAdmin.net/ under the GNU General Public License. phpMyAdmin is such a valued administration tool that it is used by majority of PHP programmers.
It is not only stable but also reliable even in worst conditions.
Features and Capabilities
phpMyAdmin offers a lot of features; some of which are:
1) Allows easy remote management of MySQL databases from any place with internet access. Create, copy, drop, rename and alter databases, tables, columns and indexes.
2) Gives complete control on privileges, passwords, and resource usage, as well as create, delete, and edit user accounts.
3) Live data are available for viewing, reports, processing through queries or stored procedures.
4) phpMyAdmin offers a highly optimized Explain utility that pinpoint queries that are slow and inefficient.
5) Export data to various formats: CSV, XML, PDF, ISO/IEC 26300.
6) Import data and MySQL structures from spreadsheets, as well as XML, CSV, and SQL files.
phpMyAdmin and XAMPP
No installation is required for phpMyAdmin. That is, if you are using XAMPP as your development platform. phpMyAdmin is one of the tools incorporated by Apache Friends in XAMPP.
Image Editor
Introducing GIMP
GIMP was initially created as the GNU Image Manipulation Program. Now, popularly known as GIMP, it evolved in its complexity and ease of use.
GIMP is an image editing tool. It is modular and accepts plug-ins and tools. It's a paint and drawing tool and conversion tool, at the same time, with features like effects, layers and filters. But do not be discouraged by GIMP's complexity. It is user friendly with a logical and intuitive user interface. Also, it sports several Help assistance; context sensitive Help, Standard Help and User Manual.
Features and Capabilities
GIMP offers a lot of features; some of which are:
•Full suite of painting tools including Brush, Pencil, Airbrush, Clone, etc.
•Sub-pixel sampling for all paint tools for high quality anti-aliasing
•Extremely powerful gradient editor and blend tool
•Supports custom brushes and patterns
•Virtually unlimited number of images open at one time
•Advanced Manipulation
•Layers and channels
•Multiple Undo/Redo (limited only by diskspace)
•Editable text layers
•Transformation tools including rotate, scale, shear and flip
•Selection tools including rectangle, rounded rectangle, ellipse, free, fuzzy
•Foreground extraction tool
•Over 100 plug-ins already available
•Animation
•File Handling
•File formats supported include bmp, gif, jpeg, mng, pcx, pdf, png, ps, psd, svg, tiff, tga, xpm, and many others
•Load, display, convert, save to many file formats
Installing GIMP
Step 1 Go to http://www.gimp.org/downloads/ and download GIMP. Download the latest stable version based on your operating system. Once you downloaded the installation file, gimp-2.8.10-setup.exe, run it. You will be presented with the first screen: Select Setup Language. Default is English. Click the OK button.
Step 2 The next screen is the Setup Gimp screen. Click the button Install.
Step 3 The next screen will extract and install GIMP files. Wait until finished.
Step 4 Once the setup is complete, the finish screen will appear. Left-click the Finish button and you are done.
GIMP Tutorials
The web site of GIMP also features comprehensive tutorials for beginners, intermediate, and advance users. Just go to http://www.gimp.org/tutorials/ and select the tutorial suited to your level.
This is an excerpt from the book "BASIC PHP" by June Bancale (coming soon)
Part 7 on PHP Programming Style..
TIPS ON PERFORMANCE
1) Use faster functions and statements.
a) Always use echo instead of print; It is much faster and less confusing
literally.
b) Use echo’s multiple parameters instead of string concatenation.
c) Always use sprintf rather than str_replace. It is palpably faster.
d) Always use sprintf instead of variables contained in double quotes.
e) using undefined variables is slower than pre- initialized variables.
f) Use the more efficient switch..case statement instead of if..elseif
statement.
g) Always use single quotes; double quotes usually takes longer to
to process since php looks for variables inside double quotes.
h) Use require over require_once to ensure fast loading and caching.
i) Use include over include_once to ensure fast loading and caching.
2) Use faster processes, functions and statements.
a) For loop: Put the max value in a variable before using in a for-loop.
b) Database access is slow. If you want to store a small amount of data, try
putting it in text files. Accessing files is faster than accessing databases.
c) Error suppression with @ is discouraged. It is slow.
d) Initialize local variables at the start of a program or function
e) Use error_reporting(E_ALL) during debug; but change to
error_reporting(E_ERROR | E_WARNING | E_USER_ERROR |
E_USER_WARNING ) when shifting to live.
3) Free memory after use.
a) Always assign null to your variables after use, to free memory.
b) Put memory intensive processes inside user defined functions.
Memory is automatically cleared upon function exit.
4) Maintainability and readability is of paramount importance than
speed or performance. Where you have to choose between the
two, choose maintainability; easy to read, easy to debug.
5) When speed is critical, optimize first the hardware. Upgrade on
processor and additional memory.
6) Optimize database queries. More often than not, a query is the
cause of speed degradation of a program.
7) Optimize your web server’s harddisk access. The slowest
component of a computer is the harddisk. So it is only prudent to
minimize harddisk accession.
8) Optimize HTML. Next to queries, inefficient HTML is the culprit
when it comes to speed problems.
to be continued...
Click here to claim your Sponsored Listing.
Category
Website
Address
136 Everlasting Street, Bulihan
Malolos
3000