I don't think that anyone has attempted to implement prolog natively in php. What you would to is think of a way to implement the rules and stuff, it's been years since I've looked at prolog all I remember is that it's a pain in the ass, in php. So that I could make a call to one of your functions to add rules to a database. Then I could make a call to another one of your functions to query the database wiwth prolog syntax. It'd probably require writting a language extension in c.
As for safe mode see http://www.php.net