PHP — Part II

Web-Based Services (INFOSYS 290-3)

Erik Wilde, UC Berkeley iSchool
Wednesday, September 27, 2006
Creative Commons License

This work is licensed under a Creative Commons
Attribution-NonCommercial-ShareAlike 2.5 License.

Abstract

PHP is a server-based technology, but it can also act as a client. Using additional packages, a PHP script can request information from other servers. Snoopy is such an example, it implements HTTP and allows users to request resources from Web servers. In addition, Snoopy supports a methods to access these resources. The goal of this lecture is to introduce Snoopy so that it can serve as a foundation for further experiments when implementing Web-based services.

PHP Form Processing

Server-Side Implementation

$command = $saxon . ' dret.xml bibquery.xsl author=' . pass_string($formval_author) . ' format=html' ;
system ($command) ;

Interface vs. Implementation

Outline (Snoopy)

  1. Snoopy [4]
  2. Bibliography Querying [6]
  3. Conclusions [2]

Reaching Out

Fetching Resources

<?php 
include "../a/3/Snoopy.class.php";
$snoopy = new Snoopy;

$snoopy->fetch("http://www.ischool.berkeley.edu/");
print $snoopy->results;
?>
<?php
include "../a/3/Snoopy.class.php";
$snoopy = new Snoopy;

$snoopy->fetchtext("http://www.ischool.berkeley.edu/");
print $snoopy->results;
?>

HTTP Headers

<?php
include "../a/3/Snoopy.class.php";
$snoopy = new Snoopy;

if($snoopy->fetch("http://www.ischool.berkeley.edu/"))
{
    echo "response code: ".$snoopy->response_code."<br>\n";
    while(list($key,$val) = each($snoopy->headers))
        echo $key.": ".$val."<br>\n";
    echo "<p>\n";

    echo "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
}
else
    echo "error fetching document: ".$snoopy->error."\n";
?>

HTML Links

<?php
include "../a/3/Snoopy.class.php";
$snoopy = new Snoopy;

$snoopy->fetchlinks("http://www.ischool.berkeley.edu/");

while(list($key,$val) = each($snoopy->results))
 echo $key.": ".$val."<br>\n";
?>

Outline (Bibliography Querying)

  1. Snoopy [4]
  2. Bibliography Querying [6]
  3. Conclusions [2]

Using Parameters

Author Names

query?author=Hoare
query?author=Harry

Entry Titles

query?title=XSLT
query?title=Markup

Full-Text Search

query?fulltext=XDBMS
query?fulltext=xml+modeling

Entry Types

query?type=book
query?type=thesis

Date Ranges

query?end=1950
query?start=2006-09&end=2006-09

Outline (Conclusions)

  1. Snoopy [4]
  2. Bibliography Querying [6]
  3. Conclusions [2]

Simple Server-Side Scripting

Assignment 3