Problem with PHP and Prolog

121 views
Skip to first unread message

Nestor Daniel Campos Camacho

unread,
Jul 7, 2016, 8:34:57 PM7/7/16
to swi-p...@googlegroups.com
First of all, sorry for my bad english.

I'm trying to make an expert system with Prolog and PHP. I'm using MAMP and just make PHP work with Prolog (a simple function that returns "hi world" is called from PHP and it shows the text in HTML). This is the code I have for it:


<!DOCTYPE html>
<html>
<head>
<title> Test </title>
</head>
<body>

<?php

$direccionSWIPL = "/Applications/SWI-Prolog.app/Contents/MacOS/swipl";
$direccionArchivo = "/Users/Galaners/Documents/Desarrollo/Prolog/testVocacionalV0.2.pl";

$cmd = "nice -n15 $direccionSWIPL -f $direccionArchivo -g iniciar,halt";
$output = shell_exec($cmd);
echo($output);

?>


</body>
</html>

The function "iniciar" is supposed to ask the first question, lets say something like: "do you like dogs?" and it should wait for the answer: "yes". But instead it freeze there, once you call the function "iniciar" the web pages freezes and doesn't show anything. I debug it with Netbeans and the problem is that it show in the web page the first question, but it doesn't wait for an answer and instead it show the second question and so on in an infinite cycle.
I need a way to make it ask the first question, wait for the user to answer it and then ask the second question but I can't find anything about it. Any help is welcome. I try with WAMP in Windows but it doesn't even make the connection between Prolog and PHP correctly, but I guess it could be the same result.

Anne Ogborn

unread,
Jul 8, 2016, 1:56:17 PM7/8/16
to Nestor Daniel Campos Camacho, SWI-Prolog

Hi Nestor.

HTTP inherently is an ask-answer protocol, so your approach isn't going to work.

You need to either use a console like SWISH. What you probably want is
http://www.swi-prolog.org/pack/list?p=webconsole

but unfortunately it needs some updating.You could make your own interactor using pengines.
That's probably the simplest.

But your underlying issue is trying to use HTTP as a telnet-type protocol.

You also need to think about how you'll preserve state, and how you'll keep that state separated for different users on different machines.
Reply all
Reply to author
Forward
0 new messages