Web-PHP-Metacard Process FAQ
Pierre Sahores
psahores at easynet.fr
Tue Jul 16 06:03:00 EDT 2002
Sivakatirswami wrote:
>
> Pierre:
>
> Your praises of Metacard as a long running process on a web server linked to
> a PHP front end etc. are very intriguing. Unfortunately for the untutored it
> is bit of a mystery... I looked at the archives of Metacard but they only go
> back to Nov 2001 and so your Posts with samples scripts and more thorough
> explanations... I can't find them. Do you have a FAQ on this somewhere with
> examples, diagram and a few scripts, sample HTML pages?
>
> Hinduism Today
>
> Sivakatirswami
> Editor's Assistant/Production Manager
> katir at hindu.org
> www.HinduismToday.com, www.HimalayanAcademy.com,
> www.Gurudeva.org, www.hindu.org
>
> _______________________________________________
> metacard mailing list
> metacard at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/metacard
First : Do you have a linux box with apache, php and mc installed on it
? (If yes, it will be a piece of cake to explain how to run MC as a
WAS).
Second : How to get MC running in a long process mode, even in console
mode (without XWindows)
> Pierre Sahores wrote:
> >
> > Just alike you start other console apps from the bash prompt. To test
> > this, just launch, from the shell, a new "test.mc" stack that only
> > contains :
> >
> > on openstack
> > put "Hello World"
> > end openstack
> >
> > in typing "/home/pierre/startcmc &" at the prompt where startmc, set
> > with an executable permission, contains :
> >
> > #!/home/pierre/mc
> > on startup
> > open stack "/home/pierre/test.mc"
> > end startup
> >
> > If all is right done, you will see the "Hello World" ansered at
> > prompt... and, in opening "KSysGuard", you will see the "startmc" line
> > entry, as a still running process...
> >
> > > doesn't it need X?
> >
> > No. You need just an rc.d (level 3) bash starter script pointing to the
> > stack you want to launch in the background (see the list archives). The
> > only metatalk feature unavailable in console mode is the "idle"
> > function. Is'n it great (Thanks again and again, Scott...) ?
> >
> This is really nice, thanks for the tip.
> >
> > Have fun, Pierre Sahores
> >
> > WEB & VPN applications & databases servers
> > Inspection académique de Seine-Saint-Denis
> > Qualifier & produire l'avantage compétitif
> Andu
>
Tree : Put this in the stack script of your first MC-based WAS
> 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 empty into Retour
> set itemdelimiter to "&"
> doswitcher
> write Retour to socket x
> close socket x # x = adresse IP & "|" & n° d'ordre du socket fils reçu de wmc.xml
> 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 "TEST=1"
> then Comtest1
> else if char 1 to 6 of item 1 of PostIn is "TEST=2"
> then Comtest2
> end doswitcher
>
> on PreOpenStack
> if the short name of this stack is not "WMCEC" then pass PreOpenStack
> put " Please, wait. WMC-3 server loading..."
> set twelveHourTime to false
> put "WMC-3 TCP/IP SEARCH/DB/APP'S server up since" && the short date & "," && the short time
> set the socketTimeoutInterval to "10"
> if the windows is "WMCEC"
> then accept connections on port "732" with message "newconnect"
> else accept connections on port "7321" with message "newconnect"
> open file Lepath & "LOGia931.txt" for append
> openstack
> end PreOpenStack
>
> on openstack
> if the windows is not "WMCEC" then
> set the rect of window "message box" to "504,60,936,87"
> set the rect of window "WMCEC" to "504,113,936,237"
> if "home" is in the windows
> then hide window "home"
> end if
> if the windows contains "Atelier" then close stack "Atelier"
> end openstack
>
> on Comtest1
> global Retour
> put "Hello Metacardians !" into Retour
> end Comtest1
>
> on Comtest2
> global PostIn,Retour
> put PostIn into Retour
> end Comtest2
>
Four : the PHP sockets-listener cgi-script (webmc.php)
> <?
>
> if ($REQUEST_METHOD == POST) {
>
> $headers = $HTTP_POST_VARS;
> while (list($header, $value) = each($headers)) $exAE .= "$header=$value&";
> $exAE = urlencode($exAE);
> $activapp = substr($exAE,0,5);
>
> if ($activapp == "TEST=") {
>
> $connection = fsockopen("localhost", "765", &$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", "7654", &$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");
> }
> }
>
> elseif ($activapp == "PROD=") { // if you wants to have a second WAS running beside the first one, on its how socket port...
>
> $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 {
> $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 print("erreur numéro $error_number ($error_description)<BR>\n");
> }
> }
> }
> 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");
>
> }
>
> ?>
Five : Just build a simple webmc.php html form containing this
> <html><head></head><body>
> <table><tr><td>
> <FORM ACTION="wmc.xml" METHOD="POST">
> <INPUT TYPE="HIDDEN" NAME="ia732" VALUE="1">
> <INPUT TYPE="HIDDEN" VALUE="#MTNV#" NAME="CCL">
> <INPUT TYPE="HIDDEN" VALUE="<? print("$REMOTE_ADDR"); ?>" NAME="IPC">
> <input type="password" name="TDR" size="12"><b>
> <spacer type=block height=1 width=15>
> <input type="password" name="TDS" size="12">
> <spacer type=block height=1 width=15>
> </td><td align=left valign=bottom width=40%>
> <input type=submit value=" Valider ">
> </td></tr></table>
> </form></body></html>
Just the basics... Ask for more if those explanations are not clear
enough, else have fun and thanks to Scott to be Scott ;-)
Regards, Pierre Sahores
WEB & VPN applications & databases servers
Inspection académique de Seine-Saint-Denis
Qualifier & produire l'avantage compétitif
More information about the metacard
mailing list