Friday, January 2, 2009

5 Tips To Speed Up PHP Development by Dennis Pallett

Introduction

As PHP developers, we all like to create our PHP scripts as fast as possible, and we try to take any shortcuts that we have. In some sense we are quite lazy, and we hate doing all the grunt work. That's why I'm going to give you five tips to really speed up your PHP development, and save some serious time. If you're an experienced PHP developer, these tips will probably seem very obvious to you, so this article is geared more towards beginners.

Tip #1 - Use a good editor or IDE

Using a good editor can really save you time. If you're still stuck on using Notepad to edit your PHP scripts, switch right now. There are plenty of free alternatives around, such as PHPEdit
or EditPlus 2 (Shareware). The biggest advantage you get with a proper editor is code highlighting (automatically coloring your code). Code highlighting can help you debug your scripts, or follow code logic. Most editors support code highlighting, and if yours doesn't, then you know it's not suited for coding.

Another great advantage of using a good editor is the ability to do powerful search-and-replace operations. I know for a fact that EditPlus 2 supports regular expressions in their search-and-replace functionality, and I bet most editors do. It just makes it so much easier to replace a snippet of code. Imagine having to replace something by hand hundreds of times. Think of the time that gets wasted.

You can also use a full-blown PHP IDE (Integrated evelopment Environment). Unfortunately, there aren't many PHP IDE's, and most of them are quite steep in license fees. The best one on the market is Zend Studio, by Zend
(the company backing PHP). An IDE can really save you time, by making the debugging process easier, and some IDE's (such as Zend Studio) also include IntelliSense, which will help you with function names and such (e.g. you start typing file_get.. IntelliSense shows a dropdown that matches what you were typing. It's brilliant).

In short, use a good PHP editor or IDE, and you'll save a massive amount of time!

Tip #2 - Use a framework or skeleton

Most of your PHP scripts will probably do many of the same tasks, such as database functionality (insert, update, select, delete), and have many of the same functions. You could re-write these functions and tasks every time you start a new project, but that seems a bit pointless. Instead, you could use an existing framework or skeleton, and base your new scripts on that.

You can either use a full-blown PHP framework, like CakePHP
or the Seagull Framework, but you can also use a very simple skeleton that you create yourself. It doesn't have
to be complicated at all, and can even be just one file which contains all the functions you commonly use.

If you've already written part of your new script, you've already saved time, no matter how much or little you've already written. If you use a framework, the structure of your script has also been determined already (largely), which can also save time.

In short, you should try to re-use as much code as you can, and try to create (or download) some short of skeleton or framework to really speed up development.

Tip #3 - Don't re-invent the wheel

Continuing the previous tip, something that really speeds up development is using existing solutions. I'm not talking about a skeleton or framework, but using a full-blown script, and customizing it to your needs.

If you're going to build a CMS for your website, which is actually one of the most common things PHP developers create, then you should first look at existing scripts. There are plenty of great scripts already, and many of them are completely free, often licensed under an open source license, such as the GPL license.

A good example of this is WordPress. Originally, WordPress
is a blogging tool, but it can easily be used as a CMS for your website, and you can even extend it using template hacks, plugins or code modifications. This will save you a significant amount of time, which means you can focus your
time on other tasks.

Of course in some situations, when you have really specific needs, it won't be possibly to use an existing script, but before you start, try and find something that resembles your needs. Have a look on HotScripts and search Google. There's a big chance that it already exists.

Tip #4 - KISS (Keep It Simple Stupid)

During the development of a new script, you will probably run across many problems, and you'll have to think of a good solution. The best way is to keep the solution as simple as possible, and as soon as you notice that your code becomes 'filthy', you should consider re-doing it in another way. By filthy I mean overly complicated, and believe me, I've written plenty of filthy code myself.

You get started on some solution, but along the way, you discover more problems, and instead of taking a step back and looking at what the actual problem is, you furiously
code along. This might seem to save time, but in the long run you will only end up with thorny code, that is hard to understand.

The best way is to make everything as simple as possible. I keep everything as short as possible, and my if-statements and loops are never longer than 10-20 lines. If they become longer, I will first look if I can't do it simpler, and if that's not possible, I break it up in blocks, to make it easier to follow.

In some cases I rewrite a particular block of code 3 or 4 times. This might seem a huge waste of time, but it will save you a huge amount of time in the long run.

So in short, try to keep everything as simple as possible. You should be able to immediately understand what's happening, without having to read a huge API guide or the comments.

Tip #5 - Document your code

Another great way to speed up development is to properly document your code, especially the complicated parts. However, you shouldn't over do it. The style of comments below is ridiculous, and completely pointless:



  1. // Opening connection

  2. $linkid = mysql_connect ('localhost', 'sa', 'pass');

  3. // Selecting database

  4. mysql_select_db('mydb', $linkid);

  5. // Running a query

  6. $query = mysql_query ("SELECT * FROM bla");

  7. // etc...


  8. ?>



As you can see, the comments add no value at all. Just by quickly glancing, you can figure it everything the comments say, so the comments don't serve any purpose at all. Better would be something like this:




  1. // Get our content from database

  2. $linkid = mysql_connect ('localhost', 'sa', 'pass');

  3. mysql_select_db('mydb', $linkid);

  4. $query = mysql_query ("SELECT * FROM bla");

  5. // Below is the code for our search algorithm

  6. // This algorithm first looks for a certain keyword

  7. // and the orders it on relevancy


  8. // ... code for algorithm goes here ...


  9. // Now we must make sure that all the posts

  10. // are filtered through the sensor.

  11. // This sensor checks each post, and looks for bad stuff (tm)


  12. // ... code for sensor check ...


  13. ?>



This is already much better, because we immediately know what the purpose is a of certain code block. From there we can then figure out how the code actually works.

Even this style of commenting isn't perfect, but there isn't a "perfect" style of commenting. Each developer has his or her own style, but make sure that other developers can read your code as well. This is especially important
when you work in a team.

If you properly document your code, you will be able to understand it much easier later on, which means you won't have to spend (much) time on figuring out what the code actually does, and can immediately start writing new code.
Good documentation can really save you a good de

Conclusion

In this article I have shown you five ways to shorten your development time and being able to release faster. I must tell though you that the above tips don't always work, but even if you only use one or two shortcuts, you've already
saved precious time.

If you have any tips yourself, or would like to comment on one of the tips above, feel free to leave your comments below.

al of time.


What is PHP? by David Sklar and Adam Trachtenberg

PHP is a server-side scripting language for creating dynamic Web pages. You create pages with PHP and HTML. When a visitor opens the page, the server processes the PHP commands and then sends the results to the visitor's browser, just as with ASP or ColdFusion. Unlike ASP or ColdFusion, however, PHP is Open Source and cross-platform. PHP runs on Windows NT and many Unix versions, and it can be built as an Apache module and as a binary that can run as a CGI. When built as an Apache module, PHP is especially lightweight and speedy. Without any process creation overhead, it can return results quickly, but it doesn't require the tuning of mod_perl to keep your server's memory image small. In addition to manipulating the content of your pages, PHP can also send HTTP headers. You can set cookies, manage authentication, and redirect users. It offers excellent connectivity to many databases (and ODBC), and integration with various external libraries that let you do everything from generating PDF documents to parsing XML.

PHP goes right into your Web pages, so there's no need for a special development environment or IDE. You start a block of PHP code with or even ) The PHP engine processes everything between those tags.

PHP's language syntax is similar to C's and Perl's. You don't have to declare variables before you use them, and it's easy to create arrays and hashes (associative arrays). PHP even has some rudimentary object-oriented features, providing a helpful way to organize and encapsulate your code.

Although PHP runs fastest embedded in Apache, there are instructions on the PHP Web site for seamless setup with Microsoft IIS and Netscape Enterprise Server. If you don't already have a copy of PHP, you can download it at the official Web site. You'll also find a manual that documents all of PHP's functions and features.

Create Your Own Commands

Because PHP scripts sit inside HTML documents, you don't need a special editor to create pages. You do need to be running on a server that supports PHP, however. If you run your own server, this is easy enough to do. If an ISP serves your pages, contact your ISP's support team and ask that they install PHP for you.

For Unix systems, you'll need basic Unix skills, such as using make and a C compiler, an ANSI C compiler on your system, and a Web server.

For Windows 95/NT, you'll need one of the following servers: Microsoft Personal Web Server, Microsoft Internet Information Server 3 or 4, Apache 1.3.x, or Omni HTTPd 2.0b1.

You can find all the information you need to install and configure PHP on the PHP Web site.

Quick Intro to PHP Development by Alan Grissett

Chances are that if you’ve been around the Internet long enough, you’ve heard of server-side scripting languages such as PERL, ASP and ColdFusion. These are all popular languages that are used to add interactivity to Web sites, but one stands out from the crowd in terms of usability, power, and, yes, price: the PHP scripting language. Initially developed in 1995 by North Carolina programmer Rasmus Lerdorf, PHP has since blossomed into one of the leading open-source, cross-platform scripting languages available. This is due, in large part, to the worldwide community of coders that contributes to its development. Unlike proprietary scripting languages like ASP and ColdFusion, PHP’s source code is freely available for peer review and contributions. This is, of course, the essence of open-source software development, but why is it that PHP in particular has gained such popularity among Web developers when there are other open-source alternatives, such as good old-fashioned PERL CGI scripts? One very strong reason is that PHP, unlike PERL CGI scripts, is scalable and fast. Instead of requiring the server to start a new process in the operating system’s kernel for each new request, which uses both CPU time and memory, PHP can run as a part of the Web server itself, which saves a considerable amount of processing time when dealing with multiple requests. This decreased processing time means that PHP can be used for high-traffic sites that cannot afford to have their performance hampered by relatively slow CGI scripts.

In addition to its scalability and speed, another usability factor that sets PHP apart is its ease of use. The PHP language is considered to be a mix between C and PERL, and it draws from the best features of each parent language, while adding unique features of its own. For example, PHP code can be embedded within standard HTML documents without using additional print statements or calling separate scripts to perform the processing tasks. In practice, this allows for very flexible programming practices. Although a working knowledge of HTML is a prerequisite for PHP development, PHP’s basic functions can be learned quickly and applied to a wide range of common Webmaster-related projects, such as order forms, e-mail responses, and interactive Web pages.

Contributing to the power of the PHP language, is its native support for leading relational database platforms, including MySQL, Oracle and PostgreSQL. Platform-specific functions are built into the language for 12 databases in all. This native support for database platforms is a boon to any site that needs to track user information, store product data, or collect sales information.

Last but not least, because PHP is open-source, it is essentially free to use. Almost all professional Unix-based Web hosts offer PHP as an included option with hosting accounts. Be sure to check with your host to see if it is available to you.

This article is meant to be an introduction to the PHP language and not a tutorial, but have no fear—here are several first-rate sites that have articles that will guide you along in beginning your PHP development projects:

www.php.net
www.onlamp.com/php/
www.phpbuilder.com

Thursday, January 1, 2009

Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition (Beginners / Beginning Guide)













Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition (Beginners / Beginning Guide)


Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition covers every step of the design and building process involved in creating powerful, extendable e–commerce web sites. Based around a real–world example involving a web site selling t–shirts, you’ll learn how to create and manage a product catalog, build and integrate a shopping cart, and process customer accounts and PayPal/credit card transactions.

With the e–commerce framework in place, authors Emilian Balanescu and Cristian Darie show you how to integrate advanced features sure to set your web site apart from the competition. You’ll learn how to expand your catalog using Amazon Web Services, optimize the web site for the search engines, and take advantage of Ajax to build an even more user–friendly shopping cart.

Other highlights:

  • The authors show you how to build a complex, extendable e–commerce web site using sound development practices.
  • This second edition has been updated to take advantage of a more flexible templating system, and new chapters cover Ajax integration and search engine optimization.
  • The text goes beyond basic product and customer management, showing you how to integrate product reviews, process payments using both credit cards and PayPal, and expand your web site catalog using third–party services such as Amazons affiliate program.

What you’ll learn

  • Build an extensible e–commerce web site using sound development techniques.
  • Increase sales through proven techniques such as cross–selling, upselling, and enhancing customer service offerings.
  • Expand your product and service offerings by integrating with reseller programs such as Amazon Affiliates via XML web services.
  • Take advantage of search engine optimization techniques to make your web site more easy to find.

Who is this book for?

This book was written for individuals seeking to build e–commerce web sites using the PHP language and MySQL database.


About the Apress Beginning Series


The Beginning series from Apress is the right choice to get the information you need to land that crucial entry–level job. These books will teach you a standard and important technology from the ground up because they are explicitly designed to take you from “novice to professional.” You’ll start your journey by seeing what you need to know—but without needless theory and filler. You’ll build your skill set by learning how to put together real–world projects step by step. So whether your goal is your next career challenge or a new learning opportunity, the Beginning series from Apress will take you there—it is your trusted guide through unfamiliar territory!


Related Titles

Beginning PHP and MySQL 5: From Novice to Professional, Second Edition

PHP 5 Objects, Patterns, and Practice








Beginning PHP and MySQL: From Novice to Professional, Third Edition (Beginning from Novice to Professional)














Beginning PHP and MySQL: From Novice to Professional, Third Edition (Beginning from Novice to Professional)

Beginning PHP and MySQL: From Novice to Professional, Third Edition offers a comprehensive introduction to two of the most prominent open source technologies on the planet: the PHP scripting language and the MySQL database server. Updated to introduce the features found in MySQLs most significant release to date, readers learn how to take advantage of the latest features of both technologies to build powerful, manageable, and stable web applications.

Essentially three books in one, readers not only profit from extensive introductions to the core features of each technology, but also learn how to effectively integrate the two in order to build robust data-driven applications. Packed with practical examples and insight into the real-world challenges faced by developers based on author W. Jason Gilmore's 7 years of expertise working with these technologies, readers will repeatedly return to this book as both a valuable instructional tool and reference guide.

What youll learn

  • The PHP language
  • How to back your web site with MySQL
  • Templating so that you can apply a consistent design across all pages on your site
  • How to authenticate your web site users
  • How to use cookies to maintain information (such as items in a shopping cart) while a user is browsing your site

Who is this book for?

This book is written for developers seeking to take advantage of the PHP language and MySQL database to create powerful web applications.

About the Apress Beginning Series

The Beginning series from Apress is the right choice to get the information you need to land that crucial entry-level job. These books will teach you a standard and important technology from the ground up because they are explicitly designed to take you from "novice to professional." Youll start your journey by seeing what you need to knowbut without needless theory and filler. Youll build your skill set by learning how to put together real-world projects step by step. So whether your goal is your next career challenge or a new learning opportunity, the Beginning series from Apress will take you thereit is your trusted guide through unfamiliar territory!

Related Titles

  • Beginning PHP 5 and MySQL E-Commerce: From Novice to Professional
  • Beginning Ajax with PHP: From Novice to Professional
  • PHP 5 Recipes: A Problem-Solution Approach
  • Pro PHP Security
  • PHP 5 Objects, Patterns, and Practice

Beginning PHP and Oracle: From Novice to Professional (Expert's Voice)














Beginning PHP and Oracle: From Novice to Professional (Expert's Voice)

Beginning PHP and Oracle: From Novice to Professional offers comprehensive information on using the PHP scripting language in conjunction with Oracle's database platform. PHP is one of the most prominent open source technologies in the area of web development, while Oracle is one of the most widely deployed and used database products.

You'll learn to reap the benefits of these core technologies by using them in unison to create dynamic, data-driven web applications. The book is packed with practical examples based on the many years of real-world experience of authors W Jason Gilmore and Bob Bryla. This book is an ideal read for web designers or programmers wanting to create applications with PHP in an Oracle environment.

  • The book covers a solid alternative to the "M" in the LAMP stack.
  • Database examples are based on real-world scenarios.
  • The text shows off Oracle's strong enterprise features.
  • The authors highlight Oracle's robust internationalization support.
  • Covers a solid alternative to the "M" in the LAMP stack
  • Database examples are based on real-world scenarios
  • Shows off Oracle's strong, enterprise features
  • Highlights Oracle's robust internationalization support







Beginning PHP 5, Apache, and MySQL Web Development














Beginning PHP 5, Apache, and MySQL Web Development
This update to a Wrox bestseller dives in and guides the reader through the entire process of creating dynamic, data-driven sites using the open source "AMP" model: Apache Web server, the MySQL database system, and the PHP scripting language. The team of expert authors covers PHP scripting, database management, security, integration, and e-commerce functions and comes complete with a useful syntax reference.

* Showcases three fully functional Web site examples, with implementations for both Windows and Linux, that readers can incorporate into their own projects
* Updates include a new chapter on PHP5 features and functions, a new example Web site application, and updates to PHP5 throughout the text






Chitika

Chitika list ads

Mobile Ads