Computer Science Canada

PHP Server

Author:  beard0 [ Tue Aug 31, 2004 8:51 pm ]
Post subject:  PHP Server

I'm writing my own web server in turing - and before you jump on me telling me this is the PHP help forum - what I'm looking for is help on how to comunicate with the php install that I got from php.net. Does anyone know how I would go about calling on it to interpret a file for me, and then give me the neccessary information to then send that to the client?
Thanks!

Author:  Dan [ Sun Sep 05, 2004 9:25 am ]
Post subject: 

Wow, that is some project. I am not shure if it whould be posable to directly intreface turing and php like that, since turings comands realting to anything out side it's self are limited. What you may have to do is write your own inturpiter for php or many be kind of trick it in to work with turing by using a web server that dose work with php and then geting the out put from it when it reads the php file.

May be some one who knows more about the inner workings of php can post and let us know if it whould be posable to get data from it with the limited comands turing has....

Author:  rizzix [ Sun Sep 05, 2004 10:25 am ]
Post subject: 

ok try this

/location/to/php.exe somephpfile.php

u need to somehow grab output from STDOUT (i dont know how the hell you do that in turing... unless its automatically done for you.. and you will know this if the turing command to execute external programs is a function returning a string)

Author:  Dan [ Sun Sep 05, 2004 12:48 pm ]
Post subject: 

ya thats the thing tho, i know turing can pass arugements to progmaes but i have yet to find any way of geting it to read stdin/stdout from them. The only way i could think of whould be to posable mess with pointers in turing so they will grabe the data in the ram adderes from that progame. but that whould be extreamly hard to do and i am not even shure if turing could do it ether.

I am thinking your bests bets whould be to make it read a file outputed by the php some how or write your own php interditer in turing.

Author:  rizzix [ Sun Sep 05, 2004 1:35 pm ]
Post subject: 

what about cheat and unchecked pointers. that might be the way.. i;ll give it a shot tonight.

Author:  Catalyst [ Sun Sep 05, 2004 4:09 pm ]
Post subject: 

you could write another small program that runs the php.exe then dumps stdout to a temp file that turing can go and fetch

Author:  rizzix [ Sun Sep 05, 2004 4:30 pm ]
Post subject: 

yea that should be the last resort.. cuz it would slow thing down a lot.

Author:  wtd [ Sun Sep 05, 2004 11:58 pm ]
Post subject: 

Doesn't Turing have some kind of system(prog_name) function?

Author:  beard0 [ Mon Sep 06, 2004 7:40 am ]
Post subject: 

It does, but as has been stated above, I can run the php.exe, with the desred file as an argument, bu I can not (or at least don't know how to) then access the STDOUT, which is the whole purpose of running php.exe.

Author:  wtd [ Tue Sep 07, 2004 6:54 pm ]
Post subject: 

Does the system() function return the output of the program?

Author:  Dan [ Tue Sep 07, 2004 8:46 pm ]
Post subject: 

No, just a int repsenting the if the comand was scusful or not and if not what error hapened.

I checked the sys comands and i could not see anything that whould be very helpfull for this.

Edit: i think the easyest way to do this whould be writing a 2nd progame that can comintacte between php and turing that is not writen in turing. The problem tho is that u whould have to time the reading and writing of the file right and it could be slow. Also if u are going to be doing that why not just make the webserver in that 2nd lang.

The way that whould fuction the best whould be writing your own code to read the php file and then out the same thing php.exe whould or coming up with some ingeuses way of tricking turing in to setaling the stout data like by messing with pointers.

Author:  beard0 [ Wed Sep 08, 2004 1:52 pm ]
Post subject: 

Thanks for all the help. It looks like the answer is trying to read stout, with pointers. Which means my problem now is a turing problem. I'll have to read up on how to use pointers in turing.

Thanks again!

Author:  wtd [ Wed Sep 08, 2004 2:51 pm ]
Post subject: 

Actually what I'd recommend is writing the output of the PHP command to a file ( system("php input.php > output.html") ), then reading that file.

Aside from using a language that's better at scripting tasks (Perl, Ruby, and possibly Python), this seems the best alternative.

Author:  beard0 [ Wed Sep 08, 2004 3:52 pm ]
Post subject: 

Oh wow! I didn't know of that nice little ">" command! That will do what I need at least temporarily. I can look into other methods to improve speed later. Thanks!

Author:  rizzix [ Wed Sep 08, 2004 5:54 pm ]
Post subject: 

yep as i said.. performance.. hmm but to think again.. i dont think there's another way around.. hmm.. the new OS's would immediatly terminate ur program if u try doing something funny like that.

Author:  wtd [ Wed Sep 08, 2004 7:08 pm ]
Post subject: 

beard0 wrote:
Oh wow! I didn't know of that nice little ">" command! That will do what I need at least temporarily. I can look into other methods to improve speed later. Thanks!


The ">" is just a bit of shell syntax which redirects standard output. Basically I'm saying, 'execute "php input.php" with standard output sent to the file "output.html".'

Using ">>" does the same thing, except appends to the file.

Both of these work more or less identically under *nix operating systems and Windows.

Author:  beard0 [ Sun Sep 26, 2004 8:51 pm ]
Post subject: 

This is a bit of a stretch I know, but now I'm trying to pass variables from post & get methods that are sent from the browser to my server on to the php.exe. Any ideas on the correct format for doing so? (I did try doing "php.exe phpfile.php?var1=value > out.html" but that didn't work)

Any ideas would be very appreciated.

Author:  rizzix [ Thu Sep 30, 2004 2:27 pm ]
Post subject: 

ehmm i think for cgi applications it just reads the ENV variable..

but maybe its also possible to pass arguments.. if so it could be something like: for help=1 ... php.exe test.php help 1 > test.htm

but i'm not sure

Author:  wtd [ Thu Sep 30, 2004 2:37 pm ]
Post subject: 

rizzix wrote:
ehmm i think for cgi applications it just reads the ENV variable..


It does, and this can be incredibly complex.

Author:  beard0 [ Thu Sep 30, 2004 6:30 pm ]
Post subject: 

errr... just what is the ENV variable? When I get the information say from a POST satement in the form:

Client wrote:
POST file.php HTTP/1.1

Header1: Val1
Header2: Val2
Header3: Val3

name=bob&lname=smith


is some part of that the ENV variable, or do I have to encode it to something else, being the ENV variable?

Author:  wtd [ Thu Sep 30, 2004 7:06 pm ]
Post subject: 

Environment variables define various bits of information about the computing environment you're in. They're available to any language with an API for accessing them, and include things like HOME and PATH. The former would be the absolute path to the user's home directory on the hard drive, and the latter is a list of all directories the system should automatically look in for executables.

If you create a program "foo.exe" and stick it in "C:\Stupid Programs", and "C:\Stupid Programs" is listed in PATH, then just typing "foo" at the command prompt will run the program without you having to explicitly tell the computer where to look for the actual executable.

Author:  beard0 [ Fri Oct 01, 2004 11:53 am ]
Post subject: 

So what ENV variable would php be reading, and do you have any idea weather or not turing can set it?

Author:  wtd [ Fri Oct 01, 2004 1:13 pm ]
Post subject: 

Well, a few that come to mind from my Perl days:

CONTENT_LENGTH
REQUEST_METHOD
QUERY_STRING

Author:  rizzix [ Fri Oct 01, 2004 7:20 pm ]
Post subject: 

yep well CGI is a standard.. i suggest you lookup those

oh and ur in luck.. turing has functions to access the ENVs..

code:
getenv ( symbol : string ) : string


: