Using php

Pierre Sahores psahores at easynet.fr
Wed Feb 18 14:59:14 EST 2004


Le mer 18/02/2004 à 04:16, Shari a écrit :
> >Shari,
> >
> >If you control the php script, you can always return simple HTML 
> >than will render using a field's htmlText property, and display that.
> >You can also just search for the name in the HTML.
> >
> >HTH,
> >Brian
> >
> >>The .php script can dynamically insert a person's name onto a web 
> >>page, to personally thank them or whatever.  But for my Metacard 
> >>script to go to that web page and check to make sure the name is 
> >>there, fails.  When you "get" an URL, what you are getting is the 
> >>raw HTML, not the finished page the surfer sees.
> 
> Brian,
> 
> I tried that last night, using a real web page on my site.  The php 
> script replaces a dummy word with the desired one, and the page you 
> see has the newly inserted word.  When I retrieved the page from 
> Metacard, it retrieved the raw HTML with the dummy word, not the web 
> page it produced with the newly inserted word.  Same problem I had 
> with CGI.
> 
> Am I missing something?
> 
> I need to be able to "get" what is displayed, not the raw HTML behind 
> it.  Barring that, the only solution would be to have a text file or 
> HTML page that is actually updated, not temporarily for one view, but 
> permanently.
> 
> Shari

Shari,

It's no way to have the same html page parsed by both PHP and a second
server-sided parser (including MC/Rev CGI) in the same time (in a
cascading parsing way).

What can be done instead is to use PHP as a sockets listener binded, one
side, to the standard 80 Apache's port and, second side, to an root
protected port (under 1024) or unprotected port (over 1024 - not always
a good practice) binded to an MC/Rev application launched in the
background (console or X11/Quartz modes) and including a stack script
handler set like below :

> on newconnect s # reading  the request from a new socket
>   read from socket s for 1 line with message "serverread"
> end newconnect

> on serverread x,y # processing the request
>   global PostIn,Retour,Debut,Lepath
>   put urldecode(y) into PostIn # données POST reçues de wmc.xml
>   put cr into char (length(PostIn))-1 to (length(PostIn)) of PostIn
>   put "" into Retour
>   set itemdelimiter to "&"
>   if "ia732=1" is in item 1 of PostIn then
>     put the date && the long time && item 1 of PostIn && char 5 to -1 of item -2 of PostIn && line 1 of opensockets() && \
>         char 5 to -1 of item 3 of PostIn && "200 OK" into Tolog
>   else put the date && the long time && item 1 of PostIn && encel(char 5 to -1 of item -2 of PostIn) && line 1 of opensockets() && \
>       char 5 to -1 of item 3 of PostIn && "200 OK" into Tolog
>   if length(Tolog) < 100 then doswitcher
>   else
>     put "500 REJECT" into word -2 to -1 of Tolog
>     doneterror
>   end if
>   write Retour to socket x
>   close socket x # x = adresse IP & "|" & n° d'ordre du socket fils reçu de wmc.xml
>   open file Lepath & "LogEcoles.txt" for append
>   write Tolog & cr to file Lepath & "LogEcoles.txt"
>   close file Lepath & "LogEcoles.txt"
>   repeat
>     if the num of lines in (opensockets()) > 1 then close socket line 2 of (opensockets()) else exit repeat
>   end repeat
> end serverread

> on socketTimout
> end socketTimout

> on doswitcher
>   global PostIn,Retour
>   set itemDelimiter to "&"
>   if char 1 to 6 of item 1 of PostIn is "ia732="
>   then send IA732 to btn "PRE93" of stack "WMCEC" -- what the MC/Rev app's server does goes there
> end doswitcher

> on PreOpenStack
>   set the socketTimeoutInterval to "10"
>   if the windows is "WMCEC"
>   then accept connections on port "732" with message "newconnect" -- root protected console mode
>   else accept connections on port "7321" with message "newconnect" -- unprotected graphical mode
> end PreOpenStack

The php part (example) :

> <?
> 
> if (!empty($_POST)) {			// PHP >= 4.10
> // if ($REQUEST_METHOD == POST) {	// PHP < 4.10
> 
> 	$headers = $_POST;
> 	// $headers = $HTTP_POST_VARS;
> 	while (list($header, $value) = each($headers)) $exAE .= "$header=$value&";
> 	$exAE = urlencode($exAE);
> 	$activapp = substr($exAE,0,5);
> 	
> 	if ($activapp == "ia732") {
> 
> 		$connection = fsockopen("localhost", "7321",  &$error_number, &$error_description, "30"); 	 
> 		if ($connection) {
> 			set_socket_blocking($connection, true);
> 			fputs($connection,"");
> 			fputs($connection,"$exAE"."\r\n");
> 			fpassthru($connection);
> 			}
> 		else 	{
> 			$connection = fsockopen("localhost", "732",  &$error_number, &$error_description, "30"); 	 
> 			if ($connection) {
> 				set_socket_blocking($connection, true);
> 				fputs($connection,"");
> 				fputs($connection,"$exAE"."\r\n");
> 				fpassthru($connection);
> 			}
> 			else print("erreur numéro $error_number ($error_description)<BR>\n");
> 		}
> 	}
> 		
> 	else {
> 	
> 		$connection = fsockopen("localhost", "4567",  &$error_number, &$error_description, "30"); 	 
> 		if ($connection) {
> 			set_socket_blocking($connection, true);
> 			fputs($connection,"");
> 			fputs($connection,"$exAE"."\r\n");
> 			fpassthru($connection);
> 			}
> 		else 	{
> 			$connection = fsockopen("localhost", "567",  &$error_number, &$error_description, "30"); 	 
> 			if ($connection) {
> 				set_socket_blocking($connection, true);
> 				fputs($connection,"");
> 				fputs($connection,"$exAE"."\r\n");
> 				fpassthru($connection);
> 			}
> 			else print("erreur numéro $error_number ($error_description)<BR>\n");
> 		}
> 	}	
> }
> 
> else 	{
> 
> 	// $f = $_POST['f'];
> 	$f=$HTTP_GET_VARS['f'];
> 	
> 	if (substr($f,0,6)=='/tmp/p') {
> 
> 		#Contrôle du fichier (à ne pas oublier !)
> 		if (substr($f,5,4)!='p093' or strpos($f,'.php') or strpos($f,'/') or strpos($f,'\\'))
>  			{
> 			print ("<HTML><HEAD><TITLE>ERROR: File Not Found</TITLE></HEAD>".
>        			"<BODY background='/gif/fond-maison.gif'><H1>File Not Found</H1><P>".
>         		"<H3>Nom de fichier incorrect.</H3>".
> 			"</BODY></HTML><BR>\n");
> 			exit;
> 			}
> 		if (!file_exists($f))
>  			{
> 			print ("<HTML><HEAD><TITLE>ERROR: File Not Found</TITLE></HEAD>".
>        			"<BODY background='/gif/fond-maison.gif'><H1>File Not Found</H1><P>".
>         		"<H3>Le document attendu résulte d'une publication qui n'est plus
> 			disponible. Renouvelez la requête initiale pour le recharger.</H3>".
> 			"</BODY></HTML><BR>\n");
> 			exit;
> 			}
> 		if($HTTP_ENV_VARS['USER_AGENT']=='contype')
>  			{
>  			print ("<HTML><HEAD><TITLE>ERROR: File Not Found</TITLE></HEAD>".
>        			"<BODY background='/gif/fond-maison.gif'><H1>File Not Found</H1><P>".
>         		"<H3>Pour pouvoir consulter ce document, une mise-à-jour de votre navigateur IE est nécessaire.</H3>".
> 			"</BODY></HTML><BR>\n");
> 			exit;
> 			}
> 	
> 		#Envoi du PDF
> 		header('Content-type: application/pdf');
> 		// header('Content-disposition: inline; filename=($f)');
> 		readfile($f);
> 
> 		#Suppression du fichier
> 		unlink($f);
> 		exit;
> 		}
> 	
> 	else print("<HTML><HEAD><TITLE>ERROR: File Not Found</TITLE></HEAD>".
>        	"<BODY background='/gif/fond-maison.gif'><H1>File Not Found</H1><P>".
>         "<H3>The file you have requested does not exist on this server.</H3>".
> 	"</BODY></HTML><BR>\n");
> 	
> 	}
> 
> ?>

In this way, you will be able to build rocking MC/Rev applications servers, able to run faster than the best J2EE 
solution available today (JBoss) applications servers does, instead of, just, slow and a little capricious MC/Rev CGIs.

Hope this help ;-)

-- 
Bien cordialement, Pierre Sahores

100, rue de Paris
F - 77140 Nemours

psahores at easynet.fr

GSM:   +33 6 03 95 77 70
Pro:   +33 1 41 60 52 68
Dom:   +33 1 64 45 05 33
Fax:   +33 1 64 45 05 33

Inspection académique de Seine-Saint-Denis
Applications et SGBD ACID SQL (WEB et PGI)
Penser et produire "delta de productivité"


More information about the metacard mailing list