Forum How do I...?

Trying to use PHP...

tristan
Hi all,

I am trying to use the PHP API, however I don't seem to be able to get any results at all.

Prince is installed on Centos x64 using prince-8.0-linux-amd64-static.tar.gz. Installed to /usr/local/ and is working via ssh command line.

I do get some when I generate a pdf:

prince http://www.google.com -o google.pdf


prince: http://www.google.com:8: error: htmlParseEntityRef: no name
prince: http://www.google.com:8: error: htmlParseEntityRef: expecting ';'
prince: http://www.google.com:8: error: Tag nobr invalid

But I suspect it is just unsporrted/incorrect HTML? because the PDF is generated.

I have had no success with the PHP however... I am sorry if this is completely wrong.

<?php

	require_once('prince.class.php');
	
	$prince = new Prince('/usr/local/bin/prince');
	$path = "http://www.google.com";
	
	$convert = $prince->convert_file($path);
	
	if($convert === true) {
		echo "Success";	
		
	} elseif($convert === false) {
		echo "Fail:<br><br>";
		
	} else {
		echo "Wha?:<br> ";
		echo $convert . "<br>";	
	}
	
	print_r($prince);

?>

Returns.

Fail:

Prince Object ( [exePath:private] => /usr/local/bin/prince [styleSheets:private] => [isHTML:private] => [baseURL:private] => [doXInclude:private] => 1 [httpUser:private] => [httpPassword:private] => [logFile:private] => [embedFonts:private] => 1 [compress:private] => 1 [encrypt:private] => [encryptInfo:private] => )

Where am I going wrong?
mikeday
Can you try enabling a log file with $prince->setLog("...") and specifying a path that you know is writable from PHP, perhaps /tmp/prince.log or something like that?
tristan
Ok have added that

$prince->setLog("/home/fresh/public_html/pdf/prince.log");

and

$prince->setLog("/tmp/prince.log");

[logFile:private] => /home/fresh/public_html/pdf/prince.log


The directory is defintely writeable however no log file is being written. Have tried running a via command line to but still nothing?
mikeday
Is safe_mode enabled in PHP? There may be some security permissions preventing your page from launching external processes. Perhaps try the system() function?
tristan
Safe mode was not enabled and when running:

$cmd = "date";
$output = system($cmd);


gave:

Thu Jan 12 12:01:28 EST 2012



$cmd = "prince http://www.google.com -o google.pdf";
$output = system($cmd);


Doesn't do anything either

It seems the PHP file can't access Prince at all and I'm not sure if there are any other security permissions that might need to be changed to enable this for the sub account.

Any other possible things to try?
mikeday
$cmd = "/usr/local/bin/prince --version";
$output = system($cmd);

This should result in similar output to running Prince from the command-line, eg.
Prince 8.0
Copyright 2002-2011 YesLogic Pty. Ltd.
Non-commercial License

If this produces no output, you could try temporarily adding "echo hello" to the Prince shell script, just to check whether the script is executing or not, and whether it is an issue with the script or the binary that the script invokes.
tristan
Got this working was meant to post this a little while ago now..

Changed a number of things to suit our use but needed to use...

$convert = $prince->convert_file_to_file($htmlPath);

instead of...
$convert = $prince->convert_file($htmlPath);


The prince class seems to be missing private $noAuth;
mikeday
The prince class seems to be missing private $noAuth;

What does this mean? There is no noAuth variable used in the code, is there?