Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)
From: Jan Wielemaker (jan_at_ct.xs4all.nl)
Date: 03/20/04
- Next message: Torkel Franzen: "Re: Can all clauses be represented as Horn Clauses?"
- Previous message: rod: "game of life in prolog"
- In reply to: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Next in thread: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Reply: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 20 Mar 2004 10:17:42 GMT
In article <1079725018.28535.0@echo.uk.clara.net>, Martin Sondergaard wrote:
> I wrote :
>
>> > Me too, I'd like to run a website using Prolog too.
>> >
>> > I've discovered that CGI and Prolog just don't work together.
>> > For Prolog to be used with a website something new is needed.
>
> Jan W replied :
>
>> Why? CGI is often a bit clumsy anyway, but otherwise it runs just
>> fine. All you need is a predicate to read form data and a library
>> to produce a web page.
>
> The way CGI works is like this.
>
> The user fills in a form in a Web page (an HTML page),
> then clicks the Submit button on the page.
> The page is sent to a CGI program on the web server.
> The CGI program on the web server starts up,
> generates an HTML page as a reply, then sends it back to
> the browser which sent the web form.
> Then the CGI program is shut down.
>
> So every time the user clicks on a Submit button, the CGI program
> is started up and shut down.
>
> If the program which is on the webs sever is a Prolog program,
> when the user clicks on the Submit button,
> the Prolog interpreter starts up, then it loads up the Prolog program,
> then it "consults" a Prolog database, all of which takes several seconds.
> Only then can it generate a response to send back to the browser.
> After it has send the response back to the browser,
> the Prolog interpreter is shut down again.
>
> This process is why a Prolog program can be too slow to use with CGI.
> Especially if its a large Prolog program, or if it uses a large file of
> Prolog facts.
>
> Another problem with this process is this.
> If it needs to remember data from the form, the obvious way to remember data
> is to assert it as Prolog facts. But if the Prolog interpeter is shut down
> and restarted every time the Submit button is clicked,
> these prolog facts would be forgotten.
> So if the prolog program needs to remember facts, then it needs to
> store them in a file, and read them in again.
>
> So ideally I want my Prolog program to remain open all the time,
> and it would have to handle multiple CGI calls
> without having to exit and restart all the time.
>
> Would I have to use the HTTP server,
> to keep the Prolog interpreter open, handling CGI calls?
You can avoid part of the problem by compiling the program so it starts
quicker as someone else remarked. Start time, as you indicate, is only
one of the problems. The most sensible solution is to have a Prolog system
acting as a server that stays alive (like your database engine) and have
a simple CGI client contacting this server for fast startup. This isn't
hard to program. It also allows you to place the `server' on a different
host.
> Using the SWI Prolog HTML server seems an rather indirect way
> of keeping the Prolog interpreter open, to respond to multiple CGI calls,
> but I guess I can do it this way.
You can yes, but for most situations I'd go the way described above.
Using Prolog directly probably provides better performance, so it that
is an issue I'd go that way.
Cheers --- Jan
- Next message: Torkel Franzen: "Re: Can all clauses be represented as Horn Clauses?"
- Previous message: rod: "game of life in prolog"
- In reply to: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Next in thread: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Reply: Martin Sondergaard: "Re: PSP (was: Mainstreaming Prolog a Pragmatic Approach?)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]