PHP
  Home arrow PHP arrow Page 5 - Building A Document Request Protocol Part ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
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

Building A Document Request Protocol Part 2/2
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-02-24

    Table of Contents:
  • Building A Document Request Protocol Part 2/2
  • Connecting to our SARP server
  • Logging in
  • Using SARP commands
  • Adding new content using SARP commands
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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


    Building A Document Request Protocol Part 2/2 - Adding new content using SARP commands


    (Page 5 of 6 )

    We can also use PHP's socket functions and our custom SARP commands to add new categories and articles to our SARP servers Access database. We can add a new category using the "ADD CATEGORY" SARP command, like this:

    // Add a category

    fputs($sarpHandle, "ADD CATEGORY Jaguar");

    $sarpData = fgets($sarpHandle, 1024);

    echo $sarpData;


    When our SARP server receives the "ADD CATEGORY Jaguar" command, it will add a new category called Jaguar to the categories table of our access database, and return a 104 status message, like this:

    Adding a new category

    Now that we've added Jaguar to the categories table, let's add the Jaguar XK8 to the articles table:

    fputs($sarpHandle, "ADD ARTICLE XK8 The_jag_XK8_is_an_awesome_sports_car. 230000 5");

    $sarpData = fgets($sarpHandle, 1024);

    echo "<br><br>";

    echo $sarpData;


    Because each variable passed to the ADD ARTICLE command is separated by a space, you must replace all spaces in the title and content fields with underscores. The underscores are replaced with spaces when the SARP server processes the command.

    If we retrieve a list of categories and articles again as we did earlier, then we would see that Jaguar and the XK8 have been added to our Access database:

    Jaguar and the XK8 have been added to the database

    Our SARP server has been designed so that if it receives an unknown command, it will not fail over, but rather return one single new line character and no other data:

    fputs($sarpHandle, "BLAH BLEE SCHMEE");

    $sarpData = fgets($sarpHandle, 1024);

    echo $sarpData;


    In the code above, $sarpData would contain a single new line character, and no errors would occur.

    Once we're done communicating with our SARP server, we close the socket connection using the fclose function:

    }

    else

    {

    // Connection failed

    echo "Invalid user credentials (User = $xUser)";

    }



    fclose($sarpHandle);

    }



    ?>

    More PHP Articles
    More By Mitchell Harper


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT