PHP
  Home arrow PHP arrow Page 5 - Optimizing System Performance
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Optimizing System Performance
By: Sams Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2006-11-30


    Table of Contents:
  • Optimizing System Performance
  • Optimizing Performance
  • Database Optimizations
  • Keep Your Code Simple
  • Exam Prep Questions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Optimizing System Performance - Exam Prep Questions
    ( Page 5 of 5 )

    1. How can the following line of code be improved?

      $db->query("insert into foo values($id,$bar)")
      1. Use addslashes and sprintf to avoid security holes and make the code cleaner

        B. 
        Split the query over several lines

        C.  Use mysql_query() instead of $db->query()

        D. 
        Define the table fields that will be affected by the INSERT statement 

        E.  Use mysql_query() instead of $db->query() and addslashes to avoid security hole

        Answers A, B, and D are correct. First of all, you need to ensure that the query is secure; this is done by executing addslashes (or the equivalent function for your DBMS of choice) to prevent scripting attacks. If your query is long, it's not a bad idea to split it over several lines to get a better overview of your code. Use sprintf() where possible to make the code cleaner. Finally it's always a good idea to define the table fields that will be filled by an INSERT statement to prevent unexpected errors if the table changes.

    2. You developed a big application accessed by several thousand users at the same time. Suddenly, your web server stops responding and users are getting connection errors. What could have happened?

      A.  The database server was terminated because of the unusually high amount of database accesses.

      B.The web server was misconfigured so that it ran into virtual memory usage and consequent resource starvation because of too many child processes.

      C. You didn't optimize your code design properly.

      Answer B is correct. Although it could be possible that the database server was killed because of the many requests from the users, they should at least be able to see the HTML pages from the website because the web server would still be running. If connections are timing out, it is likely that the server ran into swap space because of misconfiguration of the number of concurrent web server child processes and crashed because of resource starvation.

    3. You are in a team of developers working on a number of different business applications. Your project manager tells you that in two weeks another three PHP developers will join the team and that you have to ensure that they will be ready to dive in to the current PHP code without problems. What could you do?

      A.Write proper end user documentation on how to use the web front end.

      B. Write proper end user documentation and generate proper PHPDoc comments inside the code to get an API documentation.

      C. The absence of documentation will actually encourage the new developers to delve more deeply into the code.

      Answer B is correct—or, at least, as correct as you can get in a general situation. The key here is that you should write proper documentation at the same time as you're writing your code. You could then use a tool such as PHPDocumentor to generate a nicely formatted API documentation in HTML or PDF and make it available to any new developers who join your team.

    4. Suppose that you are receiving input from the user in the form of the string "0mydeviceid" for a field for which you only allow valid numeric values. You want to test if this variable is equal to 0 and, if it isn't, output an error. Which comparison operation should you use?

      A.  (0 = "0mydeviceid")

      B.  (0 == "0mydeviceid")

      C.  (0 === "0mydeviceid")

      D.  None of the above

      Answer D is correct. Because PHP is automatically trying to convert the string "0mydeviceid" to 0 when comparing it with the equal operator == , your condition in answer B evaluates to true even though the user input is not a valid numeric value. The expression in answer C, on the other hand, correctly determines that the user input is not a valid integer—but that will always be the case because you're likely to always receive user input in the form of a string—so, even if that string can be converted to an integer value, the identity test will fail.



     
     
    >>> More PHP Articles          >>> More By Sams Publishing
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT