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?
source to share
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. :)
source to share
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.
source to share