Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 19th, 2003, 07:33 AM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to azharmateen Send a message via Yahoo to azharmateen
Default Applications Infrastructure and Dev. Strategy.

After 3 years, today, I’ve decided back to development bench and PHP is my choice to restart. Conceptually, I know the general structure of computer applications and programming languages. Controlling point of view, I understand the importance of application architecture and framework. For a quick start, I want to get the general knowledge of PHP applications framework and hereby requesting your contribution in the following topics:

1. Is there any standard Coding Conventions available, which a large number of developers are using?

2. Any information assisting as “Best Practices” in PHP application’s architecture? Especially, for designing multi-lingual applications, security, maintenance, back-up and mirror sites.

3. Online resources pointing the ready-to-use source code and libraries.

4. Development checklists, which can help to prevent the general mistakes and common errors. Similarly, application-testing checklists for ensuring the tasks are completed successfully.

5. Development and development assisting tools.


Thanks all of you in advance for your help. And if you think I am on wrong track, please guide me appropriately.

Have a nice code (in PHP).

Azhar Mateen
 
Old August 19th, 2003, 11:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by azharmateen
1. Is there any standard Coding Conventions available, which a large number of developers are using?
There isn't any one single "coding convention" for PHP -- when you think about it, there isn't a single accepted convention for *any* language. Style debates are older and more fervently fought than the old "Vi vs. Emacs" debate.

For a decent start, though, I suggest you read through the PEAR coding standard:
  http://pear.php.net/


Quote:
quote:Originally posted by azharmateen
2. Any information assisting as "Best Practices" in PHP application’s architecture? Especially, for designing multi-lingual applications, security, maintenance, back-up and mirror sites.
Well, the best place to start learning about security and PHP is to read the PHP manual:
  http://www.php.net/security

Designing multi-lingual applications in PHP is similar to designing them in any language -- typically, you'd never output text to the user as a standalone string; you'd have one or more resource files containing ALL of the strings to be displayed to the user, and display the variable corresponding to that string.

For example, here is an example of a multilingual "Hello, world";

[code]
<?php // config.inc.php

$default_lang = 'en';
$language_codes = array('en', // English
                        'es', // Spanish
                        'fr'); // French

function set_lang()
{
   if(isset($_GET['lang']) &&
      in_array($_GET['lang'], $GLOBALS['language_codes']))
   {
       $GLOBALS['lang'] = $_GET['lang'];
   }
   else
   {
       $GLOBALS['lang'] = $GLOBALS['default_lang'];
   }
}

set_lang();
require_once("lang.{$lang}.inc.php"); // include proper resource file
?>

<?php // lang.en.inc.php
$hello_str = "Hello, world!";
$submit_str = "Submit";
$language_names = array("en" => "English",
                        "es" => "Spanish",
                        "fr" => "French");
?>

<?php // lang.es.inc.php
$hello_str = "¡Hola, el mundo!";
$submit_str = "Sométase";
$language_names = array("en" => "Inglés",
                        "es" => "Español",
                        "fr" => "Francés");
?>

<?php // lang.fr.inc.php
$hello_str = "Bonjour, le monde!";
$submit_str = "Soumettre";
$language_names = array("en" => "Anglais",
                        "es" => "Espagnol",
                        "fr" => "Français");
?>


<?php // main.php

require_once('config.inc.php');
  // this require_once() call sets the appropriate language
  // and includes the proper resource file.
  // The main application never outputs anything to the user,
  // it only outputs string variables defined in the resource files.

echo $hello_str;


echo "\n"; // HTML can be output by the application,
               // since it's not language-dependent.

// we'll include a short form to let the user change languages.
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"get\">\n";
echo " <select name=\"lang\">\n";
foreach($language_codes as $lang_key)
{
   // our form will preselect the current language
   $selected = ($lang == $lang_key)? " selected=\"\"" : "";
   echo " <option value=\"{$lang_key}\"{$selected}>"
      . $language_names[$lang_key]
      . "</option>\n";
}
echo " </select>\n";
echo " <input type=\"submit\" value=\"{$submit_str}\" />\n";
echo "</form>\n";

?>


Maintenance and backup -- that's more an server admin issue, not a programming one. Same thing with mirror sites. For database-driven sites, many sites use the same database server for data but use multiple web server machines to split the load of all the incoming requests and PHP processing.

Quote:
quote:Originally posted by azharmateen
3. Online resources pointing the ready-to-use source code and libraries.
Search on google for PHP. There are a lot of code repositories and user communities out there. PHP has a bunch of links on it's home page for PHP resources and communities.
  http://www.php.net/

Also try http://www.phpbuilder.com/, http://www.hotscripts.com/, etc.


Quote:
quote:Originally posted by azharmateen
4. Development checklists, which can help to prevent the general mistakes and common errors. Similarly, application-testing checklists for ensuring the tasks are completed successfully.
What's there to say here? Your development and testing checklists are nothing more than the questions "Did I finish the job I said I'd do? Does it work?"

When testing web applications, there's more than just functional testing. You need to test for erroneous user input (form validation) and load testing as well. Load testing is stressing the web server with a LOT of requests to see how the application holds up under high-traffic situations. For most people, this isn't a priority, but if an application is written inefficiently, the bottlenecks will become apparent.

Most bottlenecks in PHP applications are due to inefficient SQL queries, or queries that return wayyy too much data, only to be filtered in PHP, poor loop logic, etc.

Quote:
quote:Originally posted by azharmateen
5. Development and development assisting tools.
There are a few PHP IDEs out there, some with functional debuggers now. I don't use these, personally, but they're there. Search for "PHP IDE" in google and see what you dig up. I know that Zend (the PHP people) have their own, which is supposed to be pretty slick.



Take care,

Nik
http://www.bigaction.org/
 
Old August 20th, 2003, 11:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have to agree with everything Nik says. As for questions 1,2 and 4, there are certain absolute truths which never vary - i.e.:

"Preincremenation of variables is invariably faster than postincrementation."
"Never do 'SELECT *'"
...and so on.

For general dos and don'ts, John Coppershall wrote a pair of articles on O'Reilly's ONLamp section earlier this summer:
http://www.onlamp.com/pub/a/php/2003...undations.html
http://www.onlamp.com/pub/a/php/2003...undations.html

Both serve as a useful set of groundrules.

That said, it's worth making the obvious statement that for the majority of sites, bandwidth consumption of you scripts (unless they are doing something spectacularly bad) is less of an issue, compared to reusability and ease of maintenance, in most cases. This is not to say that efficiency is to be ignored, but if you find that, for instance, there is something like a three-to-one ratio of design/HTML guys to coders where you work, it may be easier to output everything in HEREDOCs and make it look as much like standard HTML as possible (and to Hell with the speed concerns), if it means that your HTML guys can make minor reworks to the markup without needing to ask your permission: they can treat each HEREDOC as a block of standard HTML.

It is easier to make a readable piece of code more efficient, where necessary, than is often the reverse.

As for server administration stuff, you'll very likely find that you'll be some way into your Web career before you've ever had to deal with a server of your own - and when you do have to, you'll probably be glad you didn't have to sooner. Server administration is not something you can do in a halfhearted fashion, as many companies discovered, over the backend of last week, to their (and /our/) costs. Many Web design houses use hosting companies for this reason.

IDEs are as much a source of theological debate as coding styles, and can evoke the same kind of "Mods vs. Rockers" reaction, among the knuckle-draggers, as choice of platform. I use Kate on Linux, with the necessary plugins, HTML-Kit on Windows - again using a selected list of the available plugins.

Dan





Similar Threads
Thread Thread Starter Forum Replies Last Post
help in compiling with dev c++ 4.9.9.2 Shadowfire C++ Programming 1 April 20th, 2008 05:19 PM
ASP - Design Strategy snufse ASP.NET 2.0 Basics 1 March 27th, 2008 02:17 PM
Open("/dev/lp0", O_RDWR); rinoan Linux 1 December 21st, 2006 07:04 AM
Design Strategy zoltac007 ASP.NET 1.x and 2.0 Application Design 2 October 3rd, 2006 11:56 AM
forum infrastructure rajuru Beginning PHP 2 September 5th, 2004 03:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.