Home arrow PHP arrow Page 5 - Building A Document Request Protocol Part 2/2

Building A Document Request Protocol Part 2/2

In this article, Mitchell shows us how to implement our custom SARP protocol that we created yesterday. He uses PHP and its various socket functions to send SARP commands to our SARP server to both retrieve articles and add new articles to the servers Access database.

Author Info:
By: Mitchell Harper
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
February 24, 2002
  1. · Building A Document Request Protocol Part 2/2
  2. · Connecting to our SARP server
  3. · Logging in
  4. · Using SARP commands
  5. · Adding new content using SARP commands
  6. · Conclusion

print this article

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:




// Connection failed

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





blog comments powered by Disqus

- Removing Singletons in PHP
- Singletons in PHP
- Implement Facebook Javascript SDK with PHP
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials