Sunday 25 October 2015

Browser Network tool in Developer Tools - Chrome & Firefox

The color codes for the Network tool:

Firefox
pink - DNS lookup
orange - connecting
dark slate-blue - waiting
green - receiving


Chrome
Connecting

white with pale grey outline - queuing
grey - stalled - waiting before it could be sent, incl  time spent in proxy negotiation. + while browser waits for one of Chrome's max. 6 connections per location to become available for re-use
orange - establish connection, including TCP handshakes/retries and negotiating a SSL

Request/response
green - request sent  issuing the network request. Typically a fraction of a millisecond.
green - waiting - Time to First Byte (TTFB) - incl  the latency of a round trip to the server in addition to the time spent waiting for the server to deliver the response
blue - content download - Time spent receiving the response data

Saturday 24 October 2015

Virtual hosts on LightTPD

Virtual hosts on LightTPD

http://www.cyberciti.biz/tips/howto-lighttpd-web-server-setting-up-virtual-hosting.html

LightTPD optional modules

"mod_access",
# The access module is used to deny access to files.

Options
url.access-deny
Denies access to all files with any of given trailing path names.
Default value:empty

access.deny-all
Denies access to all files.
Note: access.deny-all should be used with a conditional to limit it (only from lighty 1.5x)

-----

"mod_accesslog",

accesslog.filename
name of the file where the accesslog should be written to if syslog is not used.
if the name starts with a '|' the rest of the name is taken as the name of a process which will be spawned and will get the output
e.g.:
accesslog.filename = "/var/log/lighttpd.log" 

$HTTP["host"] == "mail.example.org" {
  accesslog.filename = "|/usr/bin/cronolog" 
}
if you have multiple workers on 1.4.x (now, the current version) and want all access logs to be written (without that, only one worker will write logs), use accesslog.filename = "\|/usr/sbin/cronolog.."
Default: disabled

"mod_alias"
The alias module is used to specify a special document-root for a given url-subset.
e.g
alias.url = ( "/cgi-bin/" => "/var/www/servers/www.example.org/cgi-bin/" )
and additional locations can be added
alias.url += ( "/content" => "/var/www/servers/www.somecontent.org/" )
Trailing slashes are stripped from the url before matching an alias.
i.e. the alias "/content/ => "/dirtocontent/" will not match the url "/content/"; 
it matches only something like "/content/somefile" or "/content/somesubdir/".

So in most cases you shouldn't use a trailing slash on the left side,
but DO use it on the right side!): 
e.g. "/content" => "/dirtocontent/"
Now 
   "/content_x1/" is mapped to "/dirtocontent/_x1", 
   "/content/" -> "/dirtocontent/" and 
   "/content/somefile" -> "/dirtocontent//somefile" (yes, double slash).

If you don't use it on the right side too, 
   "/content_x1/" is mapped to "/dirtocontent_x1"
which you probably don't want.

alias.url = (
  "/aa" => "/domain_aa_site/"
  "/somewhere/else" => "/other/docroot/"
)

#                               "mod_auth",



#                               "mod_cgi",
#                               "mod_cml",
#                               "mod_compress",
#                               "mod_evasive",
#                               "mod_evhost",
#                               "mod_expire",
#                               "mod_extforward",
#                               "mod_fastcgi",
#                               "mod_flv_streaming",
#                               "mod_magnet",
#                               "mod_mysql_vhost",
#                               "mod_proxy",
#                               "mod_redirect",
#                               "mod_rewrite",
#                               "mod_rrdtool",
#                               "mod_scgi",
#                               "mod_secdownload",
#                               "mod_setenv",
#                               "mod_simple_vhost",
#                               "mod_ssi",
                                "mod_status",
#                               "mod_trigger_b4_dl",
#                               "mod_userdir",
#                               "mod_usertrack",
#                               "mod_webdav"

Configuring LightTPD for Windows 7 - part 1 - File locations and port

Part 1a - File Locations

Stored in
<install directory>/conf/lighttpd.conf
in the server.document-root property
e.g.
server.document-root = "/var/www/servers/www.example.org/pages/" 
or
server.document-root        = server_root + "/htdocs"

Key thing: the files do not need to be stored in a sub-directory of the web-server's install directory.

Part 1b - Server Port

server.port = 3000
or
## bind to port (default: 80)
#server.port                = 80

Starting and stopping LightTPD on Windows 7

I've just done some testing with Mongoose web server on my PC.

Mongoose was taking between 600ms and 6 secsonds to serve a PHP page.

I think it's time to get something faster.

Or at least, to check to see if there is anything faster I can run on my PC.

First up LightTPD


Simply copy the contents of LightTPD.zip somewhere on your PC.

Double-click on LightTPD.exe  to start it up.

Ctrl-c in the running shell window to stop it.

LightTPD is serving it's static html default home page in 22ms.  Potentially much faster than Mongoose.


Next steps:

How to configure LightTPD to access teh html files to serve

How to configure LightTPD to serve multiple virtual hosts

How to configure LightTPD to serve PHP

Measure the speed difference






Returning to Mercurial

The way I use it:

The green tick is the screen that shows what differences have been made since last commit

The two arrows chasing their tail is the screen that lets you set where a repository looks for pushes and pulls





Tuesday 6 January 2015

Accessing a SQLite database table from PHP 5.4 upwards

Text in Courier is code to be typed literally
Text in Arial should be substituted for your own values 

<?php

try {
   $file = 'path/to/sqlfile.sl3';  // relative to the directory the php is in 
   $db = new PDO('sqlite:' . $file);  // new php db object, *not* a new db
 } 
catch(PDOException $pe) {
   echo $pe->getMessage();
   exit(0);
 }

try {
   $result = $db->query('SELECT field1,field2,field3,etc FROM table');
   echo '<table>' . "\r\n";
   echo "<tr><th>field1 name</th><th>field2 name</th><th>field3 name</th></tr>\n";
   foreach ( $result as $row ) {
      echo "<tr><td>" . $row['field1'] . "</td>" . 
           "<td>" . $row['field2'] . "</td>" .
           "<td>" . $row['field3'] . "</td>" .
           "</tr>\r\n";
   }
   echo '</table>' . "\r\n";
 } 
catch(PDOException $pe) {
   echo $pe->getMessage();
   exit(0);
 }
?>

How to get SQLite3 working in PHP 5.4, 5.5 and up - on Windows

1) Check to see if PHP believes you have SQLite3 installed and working

Create this PHP script (I created it as sqlSandbox.php in the top-level of my web-server's web root directory)

<?php
// Give yourself all the debugging info you can
error_reporting(E_ALL | E_STRICT);

ini_set('display_errors', TRUE);

// What version of PHP is running?
echo "phpversion " . phpversion();

echo "<br>";

// Everything and the Kitchen sink
phpinfo();
?>

Things to check on this page:
A) Top section
Loaded Configuration FileM:\php-5.5.10\php.ini
This shows you which php.ini file is the one to alter.
B) In the PDO section
You should see
PDO supportenabled
PDO driverssqlite

C) There should be a pdo_sqlite section.
PDO Driver for SQLite 3.xenabled
SQLite Library3.7.7.1

D) There should be a sqlite3 section
SQLite3 supportenabled
SQLite3 module version0.7-dev
SQLite Library3.7.7.1

DirectiveLocal ValueMaster Value
sqlite3.extension_dirM:\sqlite3M:\sqlite3


2) Note that any function in the PHP manual beginning "sqlite_"  refers to sqlite2 and below, and that only references beginning with SQLite3 work with SQLite3.

3) Make sure you have a php.ini file in your php directory
(I created mine by copying php-production.ini to php.ini)

4) Make sure PHP can see the PHP Windows extensions
In php.ini
Uncomment the last line of this section, (by removing the ; at the start of the line) and add the ext sub-directory

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir =

So the final line becomes:

extension_dir = ext

5) Enable the PDO Windows extension for SQLite
In php.ini
Uncomment this line (by removing the ; at the start of the line)
to get
extension=php_pdo_sqlite.dll

6) Enable the SQLite3 Windows extension
In php.ini
Uncomment this line (by removing the ; at the start of the line)
to get
extension=php_sqlite3.dll

7) Tell PHP where SQLite is.
Uncomment this line (by removing the ; at the start of the line) and put in the relevant directory
[sqlite3]
sqlite3.extension_dir = M:\sqlite3