Multiple web servers in a single 4D instance

Have you ever needed to use multiple web servers in order to, for example, split your web application code into several business units, or separate the administrator’s web server from the user’s or run an old part, not preemptive-ready yet, in a separate instance, allowing the main part to run preemptive?

If you’re nodding your head yes, then keep reading because 4D v18 R3 allows you to do so … with ease.

Database example

Manipulating web serverS

The new WEB server command allows you to manage web servers within separate objects for each server. It also accepts an optional parameter to define which server to use:

  • Web database server to manipulate the current database web server (the host database or the component database depending on where the command is called)
  • Web host database server to manipulate the host database web server from a component
  • Web request receiving server to manipulate the web server receiving a request, in a web server management common method per example.

RUNNING a component web server

For compatibility reasons, a component web server doesn’t launch itself even if its “Launch web server at startup” parameter is enabled.

To launch the component web server, you must first instantiate its web server object using the WEB server(Web database server) command. It returns an object allowing you to manage the component web server: the manipulation of start and stop.

$myComponentWebServer:=WEB Server(Web database server)

Let’s take a look at its properties :

    "name": "HDI_WebServerObject_Component1.4dbase",
    "isRunning": false,
    "defaultHomepage": "indexComponent1.html",
    "rootFolder": "/PACKAGE/WebFolder/",
    "characterSet": 106,
    "debugLog": 0,
    "HSTSEnabled": false,
    "HSTSMaxAge": 63072000,
    "HTTPCompressionLevel": 1,
    "HTTPCompressionThreshold": 1024,
    "HTTPEnabled": true,
    "HTTPPort": 8080,
    "HTTPTrace": false,
    "HTTPSEnabled": true,
    "HTTPSPort": 4431,
    "inactiveSessionTimeout": 480,
    "IPAddressToListen": "",
    "keepSession": true,
    "inactiveProcessTimeout": 480,
    "logRecording": 0,
    "maxConcurrentProcesses": 100,
    "maxRequestSize": -1,
    "maxSessions": 100,
    "sessionCookieDomain": "",
    "sessionCookieName": "4DSID",
    "sessionCookiePath": "",
    "sessionIPAddressValidation": true,
    "minTLSVersion": 3,
    "openSSLVersion": "OpenSSL 1.1.1d  10 Sep 2019",
    "perfectForwardSecrecy": false,
    "cipherSuite": "...",
    "certificateFolder": "/PACKAGE/WebCertificate/"

The web server object also includes two member methods which allow you to manage the related web server.

Starting AND STOPPING A web server

The start member method allows you to start the web server. If no parameter is set, it will start using the settings defined in the database preferences.

WEB Server(Web host database server).start()

The stop member method allows you to stop the web server.

WEB Server(Web host database server).stop()

If you want to override some settings, just create an object containing the names of the attributes corresponding to the settings you want to set with the values you want to set. All other settings will use the current database settings.

$myComponentWebServer:=WEB Server(Web database server)
$options:=New object("HTTPPort";8081;"defaultHomepage";"myCompHomepage.html")

Note that you can’t directly change the settings, you first need to stop the web server before starting it with new settings.

Listing available web servers

The new WEB Server list command returns a collection of objects corresponding to all available web servers for the host database.

$webServers:=WEB Server list

The following is a sample result from a database running its own web server and two components running their own web servers:

{"name": "HDI_WebServerObject_Host", ...}
{"name": "HDI_WebServerObject_Component1", ...}
{"name": "HDI_WebServerObject_Component2", ...}


The “On Web Connection” and “On Web Authentication” database methods can be invoked in the database receiving the request, as it has always done with legacy host database web servers. For example, if a web request is sent to a component web server and this request doesn’t fit an existing resource, the “On Web Connection” method of this component is called. It’s up to you to treat the request and reply, as is usually the case.

What about logs?

To avoid searching for web server logs in multiple places, we’ve kept them in the Logs folder of the host database. As always, the web server logs of the host database are stored in its Logs folder and each component has its own subfolder containing its web server log files.

Legacy web commands

All legacy web commands that manipulate the host database web server still target the host database, even if they are called from a component. The execution target of each legacy web command is explained in the documentation. 

Only the new web server object can handle the component’s web server. So it’s up to you to manage the different servers as you want!


• Product Owner •Damien Fuzeau has joined the 4D Product team in February 2019. As a Product Owner, he is in charge of writing user stories, then translating them to functional specifications. His job also entails making sure that the feature implementations delivered are meeting the customer needs.Damien is graduated from the University of Nantes in software engineering. He spent more than 23 years in its former company, first as developer (discovering 4D in 1997), and later as engineering manager and software architect. This company is a 4D OEM partner and deployed 4D based business softwares for thousands users, on hundreds servers. So, Damien is used to 4D development and deployment in a multi-language context.