File: demo_daemon.pl

package info (click to toggle)
swi-prolog 9.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,408 kB
  • sloc: ansic: 387,503; perl: 359,326; cpp: 6,613; lisp: 6,247; java: 5,540; sh: 3,147; javascript: 2,668; python: 1,900; ruby: 1,594; yacc: 845; makefile: 428; 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!')).