W3C home > Mailing lists > Public > www-validator@w3.org > October 2007

PHP Script - Validator Soap Request Producing Endless Slope?

From: <Grunzwanzling@gmx.li>
Date: Fri, 26 Oct 2007 15:49:46 +0200
Message-ID: <20071026134946.138790@gmx.net>
To: www-validator@w3.org

Hi,

I am new to this mailing and have not subscribed yet as I just want to
ask a question and did not know where else to look for help.

Currently, I want to build a PHP plugin for Wordpress that simply
checks on loading of each page if it is XHTML 1.0 valid. Therefore, I
call a function from the sidebar that establishes a connection to the
validator's SOAP API via the Snoopy() class (somewhat a "virtual
browser" class). If the result via SOAP returns true, a button will be
shown, if not, there will be a text that the page is invalid.

The script works SOMETIMES, but mostly it times out. When you regard
the code below, you will find a $validation_time. Normally (without
the script implemented), it takes about 3 secs for the validator to
check the code on my site www.saphod.net. With the PHP-Script
activated, it takes AGES - and by calling the php script within my
page it takes even longer.

Here is what I believed so far:
As the function calls the validator ON LOADING, the validator will
eventually call itself, thus producing an endless slope.

For this reason, I implemented an if-condition that gets the
IP-address of the remote host  - in case of the validator, this should
be 128.30.52.49, right?

Well, it made no difference. Still, the script takes AGES.

Plus:
reviewing my access.log, I realize that I get LOTS of GET-Requests
from the validator at the same time. This sounds to me as if more than
one instance tries to validate the code.

I do not know where to look next.
So, I printed the code of my script below.
I hope somebody can help me out.

Please keep in mind that I am not (yet) subscribed, so please drop me
a copy of your email.

Thanks so much in advance!

Best wishes,
Marco Luthe
www.saphod.net


******** Script code follows ******************
<?php

/*
Show XHTML validity
most of the code is from the batch validator plugin by
http://wordpress.designpraxis.at/plugins/batch-validator/
*/

function XHTML_validate_page($timeout_in_sec=NULL){

       // when given, change timeout, otherwise do not change anything and
stay default
       if (!empty($timeout_in_sec)) {
               $client->read_timeout = $timeout_in_sec;
               $client->_fp_timeout = $timeout_in_sec;
       }

       // Define URI variables
       $w3validator = "http://validator.w3.org/check?uri=";
       $uri = $w3validator . urlencode($_SERVER['HTTP_HOST'] .
$_SERVER['REQUEST_URI']);
       $uri_soap = $uri . "&output=soap12";

       // include the Snoopy class which simulates a web browser
       require_once (ABSPATH . WPINC . '/class-snoopy.php');

       // create a new Snoopy object (our "virtual browser")
       $client = new Snoopy();

       // start time of validation
       $validation_start = microtime(true);

       // Validate the URI with validator.w3.org using the SOAP API (see
http://validator.w3.org/docs/api.html for more info)
       // But: if it is the validator itself, then do nothing! Otherwise,
there might be an endless slope and a timeout
       if (@$client->fetch($uri_soap) && !($_SERVER['REMOTE_ADDR'] ==
"128.30.52.49" || $_SERVER['REMOTE_HOST'] = "validator.w3.org")) {

               // Save the results
               $data = $client->results;

               // Just for debugging reasons
               /*
               @$client->fetchtext($uri_soap);
               $data_text = $client->results;
               */

               // Search for "m:validity" and "m:doctype" in the results (again,
see the validator API)
               $data = explode("\n",$data);

               // Can I optimize these two foreach slopes into one?
               foreach ($data as $buffer) {
                       if (eregi("m:doctype",$buffer)) {
                               $doctype = trim(strip_tags($buffer));
                               break;
                       }
               }
               foreach ($data as $buffer) {
                       if (eregi("m:validity",$buffer)) {
                               $validity = trim(strip_tags($buffer));
                               break;
                       }
               }

               // again: for debugging reasons
               /*
               echo "Results:\n";
               echo "Remote Adress: " . $_SERVER['REMOTE_ADDR'];
               echo "Validity: " . $validity;
               echo "Doctype: " . $doctype;
               echo eregi("XHTML 1.0",$doctype);
               echo "Text: \n" . print($data_text);
               */

               if (!($client->timed_out)) {
                       $validation_end = microtime(true);
                       if($validity == "true" && eregi("XHTML 1.0",$doctype)) {
                               // Page is valid XHTML 1.0 transitional when $validity is true and
doctype is like "XHTML 1.0", so use the XHTML 1.0 icon as shown on
w3.org
                               echo "<a href=\"" . $uri . "&amp;ss=1\" target=\"blank\"><img
src=\"http://www.w3.org/Icons/valid-xhtml10\" alt=\"Valid XHTML 1.0
Transitional\" height=\"31\" width=\"88\" /></a>";
                       } else {
                               // Page is not valid XHTML 1.0, print a message
                               $error_message="Page is not valid XHTML 1.0<br />Automatic
validation failed.<br />[<a href=\"" . $uri . "&amp;ss=1\"
target=\"_blank\">check manually</a>]";
                               echo $error_message;
                       }
                       $validation_time = round($validation_end - $validation_start);
                       echo "<br />(" . $validation_time . " sec)";
               } else {
                       $timeout_message="Is this page valid XHTML 1.0?<br />Automatic
validation timed out.<br />[<a href=\"" . $uri . "&amp;ss=1\"
target=\"_blank\">check manually</a>]";
                       echo "<small>" . $timeout_message . "</small>";
               }
       } else {
               echo "An error occured while<br />trying to automatically<br
/>validate this site.<br />[<a href=\"" . $uri . "&amp;ss=1\"
target=\"_blank\">check manually</a>]";
       }
}

?>

--
Visit 'Marco Luthe Online' @ http://www.saphod.net
-- 
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
Received on Saturday, 27 October 2007 20:26:14 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:26 GMT