# A couple of issues with http\_server \[solved\]

**URL:** <https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268>\
**Category:** Help!\
**Created:** [February 12, 2019, 10:00pm UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268 "2019-02-12T22:00:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [February 12, 2019, 10:00pm UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/1 "2019-02-12T22:00:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 13, 2019, 8:38am UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/2 "2019-02-13T08:38:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [February 13, 2019, 10:44am UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/3 "2019-02-13T10:44:34Z")

</div>

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:

```auto
:- 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).

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [February 13, 2019, 10:46am UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/4 "2019-02-13T10:46:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [February 13, 2019, 11:12am UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/5 "2019-02-13T11:12:44Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![fsaenzperez](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/fsaenzperez/32/50_2.png) [@fsaenzperez](https://swi-prolog.discourse.group/u/fsaenzperez)\
**Post date:** [February 13, 2019, 11:57am UTC](https://swi-prolog.discourse.group/t/a-couple-of-issues-with-http-server-solved/268/6 "2019-02-13T11:57:11Z")

</div>

Perfect! As always, many thanks for your support!
