Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys... i'm developing a website using php and im aware that im just a newbie when it comes to this page and someone just said that when my website start to have traffic the website could crash... so i was wondering what are the do's and dont's on creating a dynamic website... For example i have this 2 page... the first page is this:
action.php
-> This only contains a form to be displayed (new category form). Now on this form i'm calling a page namely update.php

update.php
-> update.php contains this code
switch($action){
case 'new_user':
			
$values= array("action" => "insert",
	"table" => "mytable",
	"column" => "",
	"values" => "''" . ", " .	
	quotedstr($_POST['user_desc']) . ", " .
	quotedstr("0") . ", " .
	quotedstr(isset($_POST['can_post_blog']) ? "1" : "0") . ", " .
	quotedstr(isset($_POST['can_sell']) ? "1" : "0") . ", " .
	quotedstr(isset($_POST['page_misc_profile']) ? "1" : "0") . ""
	,
        "where" => "",
	"specialStatement" => ""			
	);
			
	$output= updateQuery($values);
	break;
default:
	$output="no";
	break;
}
echo $output;


as you can see on my update.php im not using any class or extending of class or whatsoever... will this add to the possibility that my site will crash? i dont know what should be the best approach...
Posted

1 solution

There are few unrelated issues with that. The "Web site" cannot crash otherwise an HTTP server crashes which does not really happen, maybe extremely rarely. What could happen is that your PHP code throws an exception when a HTML page is being generated.

Here is the problem: a site PHP settings should be tuned the way the unhandled exception is never shown during production. Some Web hosting providers violate this rule just because people working with this site are illiterate. At least, I faced with such situation once. This is intolerable failure; if this is the case, you should either make your provider to do it right or leave the provider as soon as possible. Ideally, you should have two separate sites: one for development and internal testing, another for production. The internal development side can use both options: to hide all exception handling if you have them unhandled in your code, or show them for debugging purpose. The production server should always hide unhandled PHP exception.

On the development side, you should not let unhandled exception. You need to handle all exceptions on the very top of the stack of your code. As to catching and handling exceptions anywhere in between, you should keep catching and handling exceptions to the absolute minimum. One of such exclusions is: sometimes you need to catch low-level and general exception, use exception information to create a semantic exception explaining the problem in more semantic terms and provide semantic exception information and throw this new exception.

If there is an exception you did not expect, you can log exception information (for example, in a special file which you should never expose), to investigate the problem later.

This can be helpful:
http://www.devshed.com/c/a/PHP/Logging-With-PHP/[^],
http://www.stanford.edu/dept/its/communications/webservices/wiki/index.php/How_to_perform_error_handling_in_PHP[^],
http://www.stanford.edu/dept/its/communications/webservices/wiki/index.php/How_to_create_logs_with_PHP[^],
http://confluence.arizona.edu/confluence/display/WEBPRACTICES/PHP[^].

—SA
 
Share this answer
 
Comments
Madzmar25 20-Feb-12 19:51pm    
Wow... thanks for the information... I was really depressed... I really thought that all my website was done immaturely... and since coding style is not really a big deal for a website to crash (am i right?)... Actually im just using class in a minimum level not like other CMS that their creating almost all module into a class... will that affect my site to crash?
Sergey Alexandrovich Kryukov 21-Feb-12 1:37am    
You are very welcome.
However, I think that coding style is very important in all cases, especially in longer term when it could make maintenance a nightmare. There are too many factor which can lead to exceptions including unhandled exceptions, so its better not to invite any troubles.

Good luck,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900