[newbie] Broadcasting?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need to rewrite this Perl script in PHP:


Being the newbie I am, if you have some handy, I could use some code
to 1) fork the process, and 2) broadcast a message on the LAN.

Thanks for any tip.

Re: Broadcasting?

You can use pcntl_fork and PHP's socket functions. Example:

if (($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
  throw new Exception(socket_strerror(socket_last_error()));

if (!socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1)) {
  throw new Exception(socket_strerror(socket_last_error()));

$msgs = array(
  'STAT Rings: 1',
  "NAME $name",
  "TTSN Call from $name",
  "NMBR $num",
  'TYPE K'

foreach ($msgs as $msg) {
  if (socket_sendto($sock, $msg, strlen($msg), 0, '',
42685) == -1) {
    throw new Exception(socket_strerror(socket_last_error()));

Quoted text here. Click to load it

Re: Broadcasting?

Quoted text here. Click to load it

You don't need to fork you could just do ...

`at now phpscript.php '$cidname' '$cidnum' '$timedata'`

Either from PHP or Perl to kick off the PHP script (note that this
will run the script in at's process group rather than the originating
processs group - to run in the same group (and ensure immediate

`phpscript.php '$cidname' '$cidnum' '$timedata' &`


Site Timeline