A CGI script could do what SerialND does without too much trouble, so why use SerialND?
Here are a few possible reasons:
- Once you've got it set up, getting a unique number out of it is as easy as reading a number out of a file.
- It saves you the trouble of writing even the little bit of code that would be required to do what it does for you.
- It saves the trouble of dealing with file locking, which would be required with a CGI script to ensure that each number was unique.
- Since it waits in the background for requests for numbers, it doesn't take any extra time or processing power to load each time it runs.
- It enables you to impose a wait time between dispensing numbers to slow down people attempting to abuse your system.
The following are required to use SerialND:
- Perl
- The ability to run daemons on your server
To get a number from SerialND, have your script open the file pointed to by $frontdoor in serialnd.pl, read one line from it, and close it.
The line that was read will be a number followed by a newline character, so you may have to do something
(like adding zero to it, running it through a trim or chop function, etc.) to ensure that it's treated as a number.
Here's some PHP code to do that:
<?php
If ($f=fopen('/path/to/frontdoor/file','r')) {
$sn=fgets($f)+0;
fclose($f);
} // else an error occurred
?>
Simple!