Page 1 of 1

a port to php

Posted: Fri Jun 06, 2003 4:56 am
by []InTeR[]
I want to explain what i want to do...

Whe take one linux server, with some apache... a littlebit of mysql and a lot of php....

Now whe have a nice working server that resonds on port 80.. And i can configure this to any port that i want....

But... Now i want to do this. Without apache...

I a other way sayed: binding a port to a specific php script. So if this script is behind port 80, i have to do all the <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> apache normalie does for you... (ps: it's for a note system ATnotes)

What do i have to do/change i'm thinking in some commandline php scripting, but how/why/when...

I allready searched the internet for this, but it's linux that i'm stuck in...

Posted: Fri Jun 06, 2003 10:19 am
by volka
you might bind a socket, accept connections and handle the requests yourself within a php script (not to mention that a scheduling for concurring requests would be nice, too)
With the words of Cpt.Picard: "But the question remains: Why? What is its purpose?" ;)
It wouldn't be easier...

Posted: Tue Jun 24, 2003 4:31 am
by []InTeR[]
The purpose... :)
It's a note system that whe use here.

The idee is, to note the 'server' with a question like. 'REQUEST CONTACT INFO ABOUT somebody'.

And the server notes the results back.

The problem is, i don't want the webserver to get in the progres..
I understeand from your functions that the script has to run 24h7?
I just want the script to run when a note is recived.

Posted: Tue Jun 24, 2003 6:53 am
by Heavy
If you don't want apache, write another server that responds to a protocol of your own choice on a port of your own choice.

The closest way to get a PHP script run on request should be a web server. If you configured for example apache to have your script as an index file, you could do:

http://your.server/?CMD=blablabla+blabla+blablabla

...and get the response you tell PHP to generate.

Isn't that easy enough?
Why write a whole new server for this?

You could go calling PHP your script as a shell command. Then there is no apache around. Binding it to a port is beyond my knowledge at the moment.

Posted: Tue Jun 24, 2003 7:02 am
by []InTeR[]
Heavy wrote: You could go calling PHP your script as a shell command. Then there is no apache around. Binding it to a port is beyond my knowledge at the moment.
That's what i want to do....
And the last thing, is the same knowledge i ame missing @ the moment.

Posted: Tue Jun 24, 2003 7:09 am
by Heavy
That's what i want to do....
Well... binding it to a port with a protocol IS creating a server. To me, it still looks like using apache is less waste of time.

Posted: Tue Jun 24, 2003 7:33 am
by volka
if already installed you might use a service like inetd to start your application/script.
But I still don't see the point ;)

Posted: Tue Jun 24, 2003 7:34 am
by []InTeR[]
The use of apache is yust out of the question :) sorry.

Posted: Wed Jun 25, 2003 8:02 am
by Gleeb
For the PHP script to only run when the port is connected to, something MUST sit between the connection and PHP. This is usually apache. If you want something else, see the options above, or make your own server to handle it all as welll as interrogate PHP. Otherwise, the script will have to sit around, busy doing nothing, until someone 'note's the script.

That's just the way it works, there is no other way that I know of (and I feel I know enough to make that a definitive reply)

Posted: Wed Jun 25, 2003 8:05 am
by []InTeR[]
Correct me if i'm wrong, but i thougt... (BIEP wrong...) that a linux script, .pl or a bash shell script, can be directly connected to a port.

Posted: Wed Jun 25, 2003 8:24 am
by Gleeb
Well, I don't know much about linux, but because the PHP binary is not a script, you may not be able to. Why not have a bash/perl script that invokes PHP and simply pipes the outpur back through? A mini apache, I guess ;)

Re: a port to php

Posted: Wed Jun 25, 2003 11:21 am
by BDKR
[]InTeR[] wrote:I want to explain what i want to do...

Whe take one linux server, with some apache... a littlebit of mysql and a lot of php....

Now whe have a nice working server that resonds on port 80.. And i can configure this to any port that i want....

But... Now i want to do this. Without apache...

I a other way sayed: binding a port to a specific php script. So if this script is behind port 80, i have to do all the s**t apache normalie does for you... (ps: it's for a note system ATnotes)

What do i have to do/change i'm thinking in some commandline php scripting, but how/why/when...

I allready searched the internet for this, but it's linux that i'm stuck in...
It seems I've seen this question somewhere before. Sitepoint was it?

Anyways, what about inetd or xinetd? Check them out. They will listen on a port and based on configuration open up a script or program based on input for a specific port.

The other option is to just write a server (in PHP) or use one of the existing ones. There is PatServer, PHPServ, and Nano. Goggle or AllTheWeb will help you find 'em.

As for writing command line scripts in PHP, it's really no big deal. Check the online manual. There is a section dedicated to this.

Cheers,
BDKR

Posted: Sun Jun 29, 2003 5:06 pm
by qartis
You may want to have a look at Nanoweb, a webserver written in PHP. It's pretty full-featured, but the source is quite easy to follow, so you could probably go through and pick out quite a few features that you don't need.

EDIT: Also, phpserv is a 1-file php daemon, with very good performance, It might be easier to adapt than Nanoweb.