Finish L10n, Scalability




CS174

Chris Pollett

May 2, 2016

Outline

gettext

We start today by finishing up our discussion of localization and internationalization begun last week.

How do we create .mo files? .po files

From .po files to .mo files, more on msgid's.

Dynamic String Translation

Quiz

Which of the following statements is true?

  1. You can use a X-Frame-Options response header to prevent XSS web-site attacks.
  2. All HTTP/1.1 protocol communication is encrypted using SSL.
  3. The writing-mode css property can be used to display vertically aligned text.

General Coding Comments

PHP Guidelines

  1. Avoid require or include commands within methods or randomly in your PHP documents. Put them at the top of the given file, try to use require_once, and try to avoid using variables to say what to require.
  2. Do not write much code out of a function or method. If you are using the MVC approach we've been discussing for the HW's then only index.php and config.php should have code that is not inside a function/method/class.
  3. In particular, use PHP's copy mode only within a function, and don't have a ?> at the end of a file.
  4. As an example, consider the following code for a Layout class suitable for rendering the boiler plate start and end html tags:
    <php
    class Layout
    {
        public $view;
    
        function __contruct($view)
        {
          $this->view = $view;
          //contructor code
        }
        function render($data)
        {
          ?>
          <html>
          <head><title><?=$data['title']; ?></title></head>
          <body>
          <?php $this->view->render($data); ?>
          </body>
          </html>     
          <?php
        }
    }
    
    This avoids headaches such as sending HTTP headers from a sessions after some HTML has been output.
  5. Make sure to de-reference associative arrays correctly:
    echo $my_assoc['my_field'];
    //not
    echo $my_assoc[my_field];
    
  6. Always use Unix paths not Windows paths -- on a Windows machine PHP auto-converts from the former to the latter. On a *nix machine though, PHP won't convert Windows paths to *nix.

Testing

Scaling a Web-site

Example Web-site Architecture

Organization of a website show squids, http servers, memcached server, databases.

Remarks on Architecture

Content Delivery Networks

Object Relational Mappings

Memcached

Running memcached

Demo of connecting to memcached as a human - set

Demo of connecting to memcached as a human - get

Some Remarks on Memcached

Using memcached in PHP

Example Memcache Test

<html>
<head><title>Memcache Test</title></head>
<body>
<h1>Test</h1>
<?php
  $memcache = new Memcache();
  $memcache->addServer("localhost", 11211, true, 1, 1, 5);
  $memcache->set("bob", "value", null, 60);
  echo "<p>".$memcache->get("bob")."</p>";
?>
</body>
</html>