views:

744

answers:

4

Hello,

I have to build up a system which listens for requests from a GPS device which is only capable of sending UDP requests. Then I am going to analyze requests hopefully by PHP if it is possible.

I do not know where to start. What do I need? Can I make use of PHP? Would it be reliable to use PHP? Can I just adjust Apache for listening UDP requests?

+2  A: 

By all accounts I think PHP should be fine for that, but I haven't done anything like that myself. You will need to look into socket programming, here's a tutorial:

http://www.devshed.com/c/a/PHP/Socket-Programming-With-PHP/

karim79
Thank you, I will dive into socket programming and figure out if I can make use of it.
celalo
+1  A: 

I do not know where to start.

You need a notion of an overall program design, and, as @karim79 pointed out, an understanding of socket programming APIs for your chosen language.

Can I just adjust Apache for listening UDP requests?

Do you mean the Apache httpd? The short answer is "no."

Use something like PEAR's System_Daemon instead.

The long answer is "yes, that is possible." Particularly with modular plugins exposing the httpd's internals, you can do Just About Anything You Want (tm) (see, for instance, mod_perl). You could beat httpd into a sort of application server for a long-running (set of?) PHP process(es) which are not themselves intrinsically HTTP-driven.

The better answer of the two is, again, "no." :)

pilcrow
System_Daemon looks pretty! I am going to give it a try. Thank you
celalo
+1  A: 

Well, PHP supports a set of Socket Functions that allow you to deal with UDP, I've used them myself to build a NSLookup class which I could specify the name server (all in UDP) and a Ping class (RAW/ICMP). It works just like the standard C/C++ socket library. But I don't really think using Apache+PHP is a good choice to build those things. If you want to stick with PHP, its better to script it as a console application.

Havenard
Yes you are right. I should manage it to be a console application.
celalo
A: 

You could just have your PHP script invoked by inetd.

caf