[ Jocelyn Ireson-Paine's Home Page | SF plot-generator | SF plot-generator source ]

SF plot generator PHP script

Every so often, people ask me how I call SWI-Prolog from PHP. So I've put up a copy of the script, as the page you're reading now. Most of it is just static HTML. The active part is the call to Prolog, between the PHP <? and ?> tags in the middle of the current page. This call is as follows:

system("nice -n15 /software/bin/pl -L128k -G128k -T128k -A128k -f /home/popx/spin/spin.pl -g spin,halt")
Here, the nice reduces the priority of the process. This reduces the load on my Internet Service Provider's machine. Doing so is not essential...; but it's polite. The /software/bin/pl invokes Prolog: that's where it lives, on my ISP's machine. The -L128k -G128k -T128k -A128k set Prolog memory limits. "Spin" is a small program, so doesn't need much memory: reducing the amount needed also reduces load. The -f /home/popx/spin/spin.pl makes Prolog consult the specified file, which is my Spin source code. And -g spin,halt causes it to execute the spin predicate defined therein; and then halt. Spin sends its output to the current output stream, which the PHP system call will send back as server output.

If you want to know how to preserve state over sessions, take a look at Traveller.

The text of the script follows:

<TITLE>SF story generator

<BODY BGCOLOR=#ffffff>

[ <A HREF="/index.html">Jocelyn Ireson-Paine's Home Page</A>
| <A HREF="/spin.html">SF plot-generator source</A>
| <A HREF="/spin_script.html">SF plot-generator PHP script</A>

<H1>SF plot generator

Reloading this page will randomly generate the plot of a simple
science-fiction story. (There is an
Excel/Excelsior version of this generator at
you can also try the
Traveller game at

  system("nice -n15 /software/bin/pl -L128k -G128k -T128k -A128k -f /home/popx/spin/spin.pl -g spin,halt")

The program is one I've used in teaching Prolog. Its content is based on
"The Science Fiction Horror Movie Pocket Computer" by Gahan Wilson, from
"The Year's Best Science Fiction No. 5", edited by Harry Harrison and
Brian Aldiss, Sphere, London, 1972. The source is <A
HREF="/spin.html">here</A>; it's running under 
<A HREF="http://www.swi-prolog.org/">SWI-Prolog</A> and <A 
HREF="http://www.php.net/">PHP</A>. If you want to know
how to call SWI-Prolog from PHP, you can see
my script <A HREF="/spin_script.html">here</A>.


<ADDRESS>31st October 2008</ADDRESS>


31st October 2008