Connecting Prolog File with PHP file
I have 开发者_如何学Pythona Prolog code data.pl
, and I need to use it from a PHP file. From my search in internet, I found this:
exec('start <path/to/prolog> -f data.pl -g elem(a,[a,b])', $output)
I've tried this with Shell-exec()
and system()
commands, but they do not work either. I've also tried to correct the directory paths, and move data.pl
to path/to/prolog
folder, and still no result. Can anybody help me on this issue?
A better approach to integrating a web application with a Prolog application can be using SWI's built-in HTTP server. It will spare you the need to load Prolog and parse the input file with every call. It also provides a more web-ish integration, as you can use AJAX and similar approaches.
If you insist on invoking the Prolog executable itself from the PHP runtime env., you'll have to provide some more details. What errors do you get in your PHP logs? Have you checked file permissions? Did you try giving full paths to both the Prolog executable and data file? Just saying "it doesn't work" is a statement, not a question.
Finally, for efficiency issues, it is advisable to compile the Prolog data file into a quick load format (QLF) instead of re-parsing it with each request.
Using the 'start' command will force the program to run in a new session, and the IO pipes are not inerited. My DOS experience is a bit rusty - but there's a lot of things which would be interpreted as shell metachars on a Unix machine in that statement. Assuming the Prolog interpreter uses STDIO, the command should be:
$cmd='C:\\Program Files\\pl\\bin\\plwin -f data.pl -g elem(a,[a,b])';
// $cmd=escapeshellcmd($cmd); // in case you're still having problems
exec($cmd, $output);
精彩评论