A couple of issues with http_server [solved]

This is only to report on a couple of issues I experienced (as a beginner with web applications) when using http_server, which might be of help to others (apologies if the issues are naive):

  1. Under Windows, it seems that the default number of workers (5) is not enough for more than 3 or 4 clients: the browser seems to wait forever for the server response. Increasing this number fixes the issue. However, Ubuntu handles this much better.

  2. I struggled with SSL not working (seemed like the server was not responding in the browser) simply because I forgot to include the library http_ssl_plugin. There were neither warnings nor errors highlighting its absence.

1 Like

Which Prolog version are we talking about? And, are you loading the individual server libraries or the new http_server.pl that configures a default reasonable server? The latter includes the library http_dyn_workers, which makes the worker scheduling dynamic. Never tested this on Windows, although I see no reason why it should not work.

Also for (2) I’d like to know how you’ve set it up. On non-Windows I advice to use http_unix_daemon.pl that takes care of all this stuff. Ideally there should be a Windows equivalent … The Unix version doesn’t work on Windows as it involves quite a few tasks that are POSIX specific such as forking, detaching from the terminal, opening ports < 1000 and then dropping rights, etc.

This was tested for SWI-Prolog 7.6.4 64 bit on Windows 10 and Ubuntu 16.04. Next are the libraries loaded and the predicate to start the server:

:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_ssl_plugin)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_error)).
:- use_module(library(http/html_write)).
:- use_module(library(http/http_header)).
:- use_module(library(http/http_multipart_plugin)).
:- use_module(library(http/http_client)).
:- use_module(library(option)).
:- use_module(library(http/http_files)).
:- use_module(library(http/js_write)).

:- initialization(server).

server :-
  http_server(http_dispatch,
    [port(443), 
     workers(Workers), 
     ssl([
      host('my_host.ucm.es'), 
      certificate_file('./my_certificate_file.crt'), 
      key_file('./my_key_file.key'),
      password('my_password')
    ])]).

So, I’m not using the new http_server.pl. I’ll try this following Section 3 (SWI-Prolog HTTP support) in the on-line manual.

For (2), I simply opened a terminal in an open account for these tests and ran swipl, but I’ll follow your advice w.r.t. http_unix_daemon.pl in Ubuntu. For Windows, I’ll try to automatically start a process at start-up (maybe with Task Planner).

Correction: workers(Workers) should say workers(20).

Thanks. As the HTTP client already autoloads the SSL plugin if the arguments demand SSL, I also added this to the server. The low worker issue is IMO addressed in 8.x, so the next user should have a smoother experience :slight_smile:

Perfect! As always, many thanks for your support!