Best Practices cont - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Best Practices cont

Description:

PEAR. PHP Extension and Application Repository ... lists and download mirrors to support the PHP/PEAR community (http://pear.php.net/manual/en/introduction.php) ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 13
Provided by: philipwi
Category:
Tags: best | cont | pear | practices

less

Transcript and Presenter's Notes

Title: Best Practices cont


1
Best Practices (cont)
  • Philip Windridge

2
Contents
  • A bit on bottlenecks
  • Consider your code
  • Caching and PEAR
  • Functions and External Files

3
Performance consideration
  • Performance is application specific
  • It involves
  • Processor
  • Memory
  • Network
  • Coding style
  • Maintainability

4
Expensive Code
  • More expensive
  • for(i 0 i lt (strlen(string) - 1) i)
    //Do something
  • for(i 0 i lt myArraymyValue i) //Do
    something
  • Less expensive
  • string_len (strlen(string)-1)
  • for(i 0 i lt string_len i) //Do
    something
  • arrayValue myArraymyValue
  • for(i 0 i lt arrayValue i) //Do
    something

5
Caching
  • Initialise
  • Determine book details to view
  • Retrieve data from data base
  • Create and output html
  • Initialise
  • Determine book details to view
  • Check cache for already generated html
  • Yes?
  • Output cached html
  • No?
  • Retrieve data from data base
  • Create and output html
  • Cache html

6
PEAR
  • PHP Extension and Application Repository
  • A structured library of open-sourced code for PHP
    users
  • A system for code distribution and package
    maintenance
  • A standard style for code written in PHP,
    specified here
  • The PHP Extension Community Library (PECL)
  • A web site, mailing lists and download mirrors to
    support the PHP/PEAR community

(http//pear.php.net/manual/en/introduction.php)
7
Recap
  • Hardware vs. software issues
  • Optimisation vs. ease of maintenance/ readability

8
Improving Your Code
  • Use functions where code can be generalised
  • Use separate files for PHP where common code will
    be used across multiple pages

9
Improving Your Code
  • Code available within the page
  • User defined functions
  • Code available across a number of web pages
  • include
  • require
  • include_once
  • require_once

10
Wk3 Exercise 1
  • Create a PHP form that will accept a percentage
    grade and convert it to the appropriate grade
    point. There are separate scales for
    undergraduate awards (BSc, HND/C) and
    postgraduate awards (MSc, MRes). Your form should
    accept a percentage value between 1-100 and what
    level the grade belongs to.

11
Wk 3 Exercise 3
  • Create a form that can accept ten string values.
    Upon posting this form with ten completed values,
    have the contents of the fields placed into an
    array. Output the array to the browser, sort
    ascending and output then sort descending and
    output. You may sort the array in any way you see
    fit.

12
Wk3 Exercise 4
  • Create a copy of exercise three and modify it so
    that it asks for the number of elements to be
    input (Hint use a loop to output form elements
    according to user choice). Start with a default
    of 10 text inputs. Produce the same output as
    exercise three with the variable number of array
    values. This exercise should, ideally, involve
    much of your exercise three solution.
Write a Comment
User Comments (0)
About PowerShow.com