I have a telnet based application that runs, and need to add support for PHP to run. So I already have the connection / Socket created and going, and socket duplicated before i createprocess run php.
I just run c:\php\php.exe Test.PHP 12345
12345 being the socket handle
Having issues finding out to just read/write from the socket. I don't need to create/bind/ect.. my main app does that already.
This works in my other child apps that are not PHP based.
Been looking around but only find examples for making a PHP that will create/bind/listen .. not just "inherit" the socket handle i want to pass it.
Socket Issue with using a duplicated active socket.
Moderator: General Moderators
Socket Issue with using a duplicated active socket.
Last edited by jdredd on Thu Jun 18, 2009 3:22 pm, edited 1 time in total.
Re: Socket Issue..
php.exe will inherit the socket but your PHP script will not.
PHP deals with sockets using resources. You need a resource - like the one returned by socket_create - to do anything. You still have to open the socket in your code.
PHP deals with sockets using resources. You need a resource - like the one returned by socket_create - to do anything. You still have to open the socket in your code.
Re: Socket Issue..
Thats what I figured, but I can't get how to create the resource and have it use the socket handle ID that passed.
Re: Socket Issue with using a duplicated active socket.
You could dup2() the socket handle to STDIN/STDOUT before executing php binary. For those fds PHP automatically creates resources, accessible as STDIN/STDOUT constants from php userland code. I guess inetd does something like this.
Re: Socket Issue with using a duplicated active socket.
Dup2 ?
I am using Delphi to create a console application that is telnet based. Being able to use PHP to be ran and display the output back to the end user would be great. Spawning other non php apps that have i have from it that use the passed socket handle work fine, but they are written in freepascal and have direct winsock access easily.
Still trying out some things but so far no luck, just missing 1 thing basically to bring it all together.
Steven
I am using Delphi to create a console application that is telnet based. Being able to use PHP to be ran and display the output back to the end user would be great. Spawning other non php apps that have i have from it that use the passed socket handle work fine, but they are written in freepascal and have direct winsock access easily.
Still trying out some things but so far no luck, just missing 1 thing basically to bring it all together.
Steven
Re: Socket Issue with using a duplicated active socket.
Oh, dup2() is a unix api call. I didn't realize you were using windows. From what I heard, under windows you can use dio functions to access open file descriptors by their numbers, but then again, Winsock handles are not files. There's a example in MSDN that shows how to achieve on windows what dup2 does on unix platforms: http://support.microsoft.com/default.as ... -us;190351jdredd wrote:Dup2 ?
Re: Socket Issue with using a duplicated active socket.
Ok... i was able to create in/out pipes in my Delphi application. So when someone telnets in.. they can use the telnet service
as usual then i have a command they can run, and it will execute PHP.EXE to run the .php file. It will pipe out to the telnet connection and they can input/output like it was nothing. I have the script doing out ANSI graphics to make it pretty.
Now my next thing is, is how to get ANSI graphics to work on the "Server" side. On the server side, you see the ansi chars and all.
Can PHP do any color changing modes in command line? If so, ill just port over my ansi parser to PHP and all my color output commands, ect. thats if PHP can do that.
Anyone know a way to get XP cmd.exe to do ansi? i can modify the config.NT file and set it to dosmode and ansi.sys , but it wont work with the php.exe as Dosmode wont run win32 apps.
as usual then i have a command they can run, and it will execute PHP.EXE to run the .php file. It will pipe out to the telnet connection and they can input/output like it was nothing. I have the script doing out ANSI graphics to make it pretty.
Now my next thing is, is how to get ANSI graphics to work on the "Server" side. On the server side, you see the ansi chars and all.
Can PHP do any color changing modes in command line? If so, ill just port over my ansi parser to PHP and all my color output commands, ect. thats if PHP can do that.
Anyone know a way to get XP cmd.exe to do ansi? i can modify the config.NT file and set it to dosmode and ansi.sys , but it wont work with the php.exe as Dosmode wont run win32 apps.
Re: Socket Issue with using a duplicated active socket.
You just output certain sequences of bytes. Actual coloring must be supported by a terminal application. The cmd.exe does not parse ansi escapes, so you will need another wrapper program, like ANSICONjdredd wrote:Can PHP do any color changing modes in command line?
Re: Socket Issue with using a duplicated active socket.
I got the localside ansi stuff taken care of.
Now that Im this far, is there a way to write new input routines?
fread / fget ... i can sepcify the length of the return.. but it doesn't limit how much they can type in initially.
I would love to have a routine that could like
getinput($input,20);
and would only allow them to type 20 chars max. but that would require to read their input char by char and decide when to
stop.
Now that Im this far, is there a way to write new input routines?
fread / fget ... i can sepcify the length of the return.. but it doesn't limit how much they can type in initially.
I would love to have a routine that could like
getinput($input,20);
and would only allow them to type 20 chars max. but that would require to read their input char by char and decide when to
stop.