Hi, is there any module for connect to a GT-M database from PHP?
I have downloaded the file phpgtcm.tar.gz but I don't understand how
it works ... :-( This script is obsolete, perhaps?
Thank you!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The PHP client for the GT.CM protocol was written for an older version of PHP and has to be migrated to the current PHP version. If you migrate it successfully, please let me know so that I can make the newer version available (if you want me to, of course).
Regards
-- Bhaskar
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have two schort scripts with an example for a global access via PHP:
M-Side:
----------------------------------------------------------------------------------------------------------------------------
PHPSRV ;Server für PHP-Routinen;JWU;20081206
;For Testing
S ^PHPTST(0)="ABC"
S ^PHPTST(1)="DEF"
J START
HALT
START S $ZT="ERR^"_$T(+0)
N DATA,PORT,SOCKET,TIMEOUT
S PORT=6001,TIMEOUT=30,TCPDEV="|TCP|"_PORT_"|"_$J
O TCPDEV:(ZLISTEN=PORT_":TCP":NODELIMITER:ATTACH="listener"):TIMEOUT:"SOCKET"
U TCPDEV W /LISTEN(1) F W /WAIT(TIMEOUT) Q:$KEY]""
S SOCKET=$P($KEY,"|",2)
J START
C TCPDEV:(SOCKET="listener")
U TCPDEV:(NODELIMITER:SOCKET=SOCKET:ZNODELAY)
LOOP ; auf Daten vom Client warten
S DATA=$$WAIT()
G:DATA="0" END
; Daten verarbeiten
;Insert your Routine here
I $P(DATA,";",1)="TEST" D TEST(DATA)
;
G LOOP
ERR ;S ^TCPERR($J)=$ZSTAT
END C TCPDEV
HALT
WAIT() N DATA,LEN
U TCPDEV
R LEN#5 G:$DEVICE END
R DATA#LEN G:$DEVICE END
Q DATA
WRITED(status,DATA)
S DATA=$TR($J($L(DATA)+3,5)," ",0)_$TR($J(status,3)," ",0)_DATA
U TCPDEV
W DATA
Q
TEST(DATA) ;Testdaten zurückgeben
N GL
S GL=$P(DATA,";",2) F S GL=$Q(@GL) Q:GL="" D WRITED(1,GL_"="_@GL)
D WRITED(2,"ZZZ")
Q
--------------------------------------------------------------------------------------------------------
PHP-Side:
--------------------------------------------------------------------------------------------------------
<?
$ip = "localhost";
$port = 6001;
function connect($ip, $port){
$ok=false;
while (!$ok){
$fp = fsockopen($ip, $port, $errno, $errstr, 5);
if (!$fp) sleep(1);
else $ok=true;
}
return $fp;
}
function send($fp, $data){
$len=strlen($data);
while (strlen($len)<5) $len="0".$len;
$data=strtoupper($len.$data);
if (fputs($fp, $data, strlen($data)));
else na();
stream_set_timeout($fp,30);
$i=0;
$response="";
while ($response=fgets($fp, fgets($fp,6)+1)){
if (strtoupper($response) != "002ZZZ"){
$daten[$i] = substr($response,3);
$i++;
}else break;
}
fclose($fp);
return $daten;
}
function na(){ print "Error in Transmission"; }
#Request starts here
$fp=connect($ip,$port);
if ($fp=="") die("Can't Connect to Server");
$daten=send($fp,"TEST;^PHPTST");
echo "<b>Answer:</b><br>";
$i=0;
while (isset($daten[$i])){
echo $daten[$i]."<br>";
$i++;
}
?>
Hope it helps someone.
Maybe Bhaskar can help me how to upload this if someone is interested.
Greets
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
****************************
****** the M routine ******
****************************
SCK ;*** Socket Server ***
S $ZT="ZGOTO "_$ZLEVEL_":ERR^SCK"
S sta=$P($KEY,S,1),sck=$P($KEY,S,2),ip=$P($KEY,S,3)
R dat:10 I '$T Q
X dat
Q
ERR S ^ERR($H)=$ZSTATUS_" : "_$G(dat)
Q
**************************************
****** and the xec.php script: ******
**************************************
<?php
// This script should be called with the 'xec' parameter,
// a string variable containing the M xecute. Example:
// xec.php?xec=W $ZV
function xec($xec) {
$res = "";
// change localhost for your GT.M ip server address
$sck = fsockopen(localhost, 30000, $errno, $errstr, 30);
if(!$sck) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($sck,$xec);
while(!feof($sck)) {
$res = $res.fgets($sck,128);
}
fclose($sck);
}
return $res;
}
$xec = $_GET['xec'];
if (isset($xec)) {
echo xec($xec);
}
?>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have had some success updating phpgtcm to work with php 4.4.9. It looks like when using the included client gtcm_gnp_client and setting all the debug options on that I can access globals but the client does not seem to work correctly. Since I have upgraded to php 5 I have put it on the back burner for now. If someone has interest in further testing drop me an email at battlebrook2003@yahoo.com and I can send you the modified source code.
I believe once it works on php 4.4.9 getting it to work on php5 will be a lot easier
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, is there any module for connect to a GT-M database from PHP?
I have downloaded the file phpgtcm.tar.gz but I don't understand how
it works ... :-( This script is obsolete, perhaps?
Thank you!
The PHP client for the GT.CM protocol was written for an older version of PHP and has to be migrated to the current PHP version. If you migrate it successfully, please let me know so that I can make the newer version available (if you want me to, of course).
Regards
-- Bhaskar
I have two schort scripts with an example for a global access via PHP:
M-Side:
----------------------------------------------------------------------------------------------------------------------------
PHPSRV ;Server für PHP-Routinen;JWU;20081206
;For Testing
S ^PHPTST(0)="ABC"
S ^PHPTST(1)="DEF"
J START
HALT
START S $ZT="ERR^"_$T(+0)
N DATA,PORT,SOCKET,TIMEOUT
S PORT=6001,TIMEOUT=30,TCPDEV="|TCP|"_PORT_"|"_$J
O TCPDEV:(ZLISTEN=PORT_":TCP":NODELIMITER:ATTACH="listener"):TIMEOUT:"SOCKET"
U TCPDEV W /LISTEN(1) F W /WAIT(TIMEOUT) Q:$KEY]""
S SOCKET=$P($KEY,"|",2)
J START
C TCPDEV:(SOCKET="listener")
U TCPDEV:(NODELIMITER:SOCKET=SOCKET:ZNODELAY)
LOOP ; auf Daten vom Client warten
S DATA=$$WAIT()
G:DATA="0" END
; Daten verarbeiten
;Insert your Routine here
I $P(DATA,";",1)="TEST" D TEST(DATA)
;
G LOOP
ERR ;S ^TCPERR($J)=$ZSTAT
END C TCPDEV
HALT
WAIT() N DATA,LEN
U TCPDEV
R LEN#5 G:$DEVICE END
R DATA#LEN G:$DEVICE END
Q DATA
WRITED(status,DATA)
S DATA=$TR($J($L(DATA)+3,5)," ",0)_$TR($J(status,3)," ",0)_DATA
U TCPDEV
W DATA
Q
TEST(DATA) ;Testdaten zurückgeben
N GL
S GL=$P(DATA,";",2) F S GL=$Q(@GL) Q:GL="" D WRITED(1,GL_"="_@GL)
D WRITED(2,"ZZZ")
Q
--------------------------------------------------------------------------------------------------------
PHP-Side:
--------------------------------------------------------------------------------------------------------
<?
$ip = "localhost";
$port = 6001;
function connect($ip, $port){
$ok=false;
while (!$ok){
$fp = fsockopen($ip, $port, $errno, $errstr, 5);
if (!$fp) sleep(1);
else $ok=true;
}
return $fp;
}
function send($fp, $data){
$len=strlen($data);
while (strlen($len)<5) $len="0".$len;
$data=strtoupper($len.$data);
if (fputs($fp, $data, strlen($data)));
else na();
stream_set_timeout($fp,30);
$i=0;
$response="";
while ($response=fgets($fp, fgets($fp,6)+1)){
if (strtoupper($response) != "002ZZZ"){
$daten[$i] = substr($response,3);
$i++;
}else break;
}
fclose($fp);
return $daten;
}
function na(){ print "Error in Transmission"; }
#Request starts here
$fp=connect($ip,$port);
if ($fp=="") die("Can't Connect to Server");
$daten=send($fp,"TEST;^PHPTST");
echo "<b>Answer:</b><br>";
$i=0;
while (isset($daten[$i])){
echo $daten[$i]."<br>";
$i++;
}
?>
Hope it helps someone.
Maybe Bhaskar can help me how to upload this if someone is interested.
Greets
Jens
thank you for your scripts, Jens!
I have created these three scripts for make a socket connection
between PHP and M, and tested the results. I hope these helps
someone:
**********************
****** m_inetd ******
**********************
#!/bin/bash
# called from inetd, default port 30000
# remember the entries in /etc/inetd.conf
# and /etc/services
#
# Sample /etc/inetd.conf:
# gtm stream tcp nowait enzo /home/enzo/m_inetd
#
# Sample /etc/services:
# gtm 30000/tcp # gt.m socket server routine
gtm_dist=/usr/local/gtm
export gtm_dist
gtmroutines=". /home/enzo/rut/ $gtm_dist"
export gtmroutines
gtmgbldir=/home/enzo/test.gld
export gtmgbldir
PATH=$PATH:$gtm_dist
export PATH
cd /home/enzo/
mumps -r SCK
****************************
****** the M routine ******
****************************
SCK ;*** Socket Server ***
S $ZT="ZGOTO "_$ZLEVEL_":ERR^SCK"
S sta=$P($KEY,S,1),sck=$P($KEY,S,2),ip=$P($KEY,S,3)
R dat:10 I '$T Q
X dat
Q
ERR S ^ERR($H)=$ZSTATUS_" : "_$G(dat)
Q
**************************************
****** and the xec.php script: ******
**************************************
<?php
// This script should be called with the 'xec' parameter,
// a string variable containing the M xecute. Example:
// xec.php?xec=W $ZV
function xec($xec) {
$res = "";
// change localhost for your GT.M ip server address
$sck = fsockopen(localhost, 30000, $errno, $errstr, 30);
if(!$sck) {
echo "$errstr ($errno)<br>\n";
} else {
fputs($sck,$xec);
while(!feof($sck)) {
$res = $res.fgets($sck,128);
}
fclose($sck);
}
return $res;
}
$xec = $_GET['xec'];
if (isset($xec)) {
echo xec($xec);
}
?>
Hello
I have had some success updating phpgtcm to work with php 4.4.9. It looks like when using the included client gtcm_gnp_client and setting all the debug options on that I can access globals but the client does not seem to work correctly. Since I have upgraded to php 5 I have put it on the back burner for now. If someone has interest in further testing drop me an email at battlebrook2003@yahoo.com and I can send you the modified source code.
I believe once it works on php 4.4.9 getting it to work on php5 will be a lot easier
Dave
Hello
Good New!! gtcm_gnp_client is now working with php5
Dave