File: demo_daemon.pl

package info (click to toggle)
swi-prolog 9.2.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84,456 kB
  • sloc: ansic: 401,705; perl: 374,799; lisp: 9,080; cpp: 8,920; java: 5,525; sh: 3,282; javascript: 2,690; python: 2,655; ruby: 1,594; yacc: 845; makefile: 440; xml: 317; sed: 12; sql: 6
file content (38 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*  Part of SWI-Prolog

    Author:  Jan Wielemaker
    E-mail:  J.Wielemaker@vu.nl
    WWW:     http://www.swi-prolog
    Copying: This example is in the public domain
*/

:- module(http_daemon, []).
:- use_module(library(http/http_unix_daemon)).
:- use_module(library(http/http_server)).

:- http_handler(/, hello, []).

/** <module> Demo running SWI-Prolog HTTP services as a Unix daemon process

The first example runs this service as   a  normal user. The server does
not produce any output. It is detached from the controlling terminal and
thus remains running if you logout.   You can use library(http/http_log)
to enable logging of the HTTP requests.

    swipl demo_daemon.pl --port=5000

The second example runs this server on a priviledged user on the default
port 80, avoiding the need for  a   proxy  server. In addition, it sends
errors, warnings and debug (see debug/3) messages to syslog deamon. Note
that the =|-q|= suppresses informational messages such as loading Prolog
files.

    sudo swipl demo_daemon.pl -- --syslog=swi-demo --user=www-data

@see library(http/http_unix_daemon) for more options to http_daemon/0.
*/


hello(_Request) :-
    reply_html_page(title('Hello'),
                    p('Hello from SWI-Prolog!')).