How to listen to UDP and use PHP

I need to create a system that listens for requests from a GPS device that can send UDP requests. Then I will parse the requests, hopefully PHP if possible.

I don't know where to start. What I need? Can I use PHP? Would it be safe to use PHP? Can I just configure Apache to listen for UDP requests?

+2


source to share


4 answers


I don't know where to start.

You need a concept of general program design and, as @ karim79 pointed out, an understanding of the socket APIs for your language of choice.

Can Apache just be configured to listen for UDP requests?

Do you mean Apache httpd

? The short answer is no.



Use something like PEAR System_Daemon

instead.

Long answer: "Yes, it is possible." In particular, with modular plugins that expose internals httpd

, you can do just about anything (tm) (see for example mod_perl

). You could beat httpd

into some sort of application server for long running (set?) PHP processes that are not based on the HTTP protocol themselves.

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

+3


source


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



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

+2


source


You can only have a PHP script called inetd

.

+2


source


Well PHP supports a set of Socket Functions that allows you to work with UDP, I used them myself to create an NSLookup class that I could specify a nameserver (all in UDP) and a Ping class (RAW / ICMP). It works the same as the C / C ++ standard socket library. But I really don't think using Apache + PHP is a good choice for doing these things. If you want to stick with PHP it is better to use the script as a console application.

+1


source







All Articles