Forum How do I...?

Basic Problem Calling from PHP

anyuzer
I'm sure I'm missing something utterly basic, but as I'm somewhat a newb at this...

I've installed prince on my Linux server which currently runs PHP 5.2.3. So far I can call prince fine from the command line and get appropriate results, but when I try to call it with the following code in a test php file:

$xml_path = "/home/uzer/public_html/magic.xml";
$prince = new Prince('/usr/local/bin/prince');
$prince->convert1($xml_path);

I get nothing. I've tried everything I can think of with messing around with the strings but to no result. Is there something obvious I missed?
mikeday
This should make Prince try to write output to /home/uzer/public_html/magic.pdf, which it may not have write permission to access when it's called from the PHP page. Try specifying an explicit output location that is guaranteed to be writable, like /tmp/magic.pdf or something like that, to see if that's the problem.
anyuzer
It works! Thanks a lot Mike.
spaff
Hi there!

If have the same Problem, nothing happens when calling via PHP-Script.

<?php

require_once('lib/prince.php');

$msgs = array();
$path = '/var/www/vhosts/<domain>/subdomains/<subdomain>/httpdocs/PrinceConversion/';

$prince = new Prince('/usr/bin/prince');

$prince->setLog($path.'plog.log');

$prince->setHTML(1);

$convert = $prince->convert_file_to_file($path.'foo.html', $path.'test.pdf');

if($convert) {
	echo 'conv_true';
} else {
	echo 'conv_false';
}

?>


But i can execute the output from $pathAndArgs without Problems:

/usr/bin/prince --server --input=html --log="/var/www/vhosts/<domain>/subdomains/<subdomain>/httpdocs/PrinceConversion/plog.log" "/var/www/vhosts/<domain>/subdomains/<subdomain>/httpdocs/PrinceConversion/foo.html" "/var/www/vhosts/<domain>/subdomains/<subdomain>/httpdocs/PrinceConversion/test.pdf"

May it be a problem that installpath is "/usr/bin" ?
I added the Path "/usr/bin" to open_basedir for this subdomain. is_file on "/usr/bin/prince" returns true.

Input and outputfolders and -files are set to rights "777"

Also tried the following without success:

<?php

require_once('lib/prince.php');

$prince = new Prince('/usr/bin/prince');

$html = '<html><body><div>TEST</div></body></html>';

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="foo.pdf"');

$prince->convert_string_to_passthru($html);

?>
mikeday
Can you successfully execute any other binaries from PHP? You could try adding "touch /tmp/prince.is.running" to the /usr/bin/prince shellscript to confirm that it is actually executing.
spaff
It works with safe_mode off. Don't know why i didn't tried this before.
But I couldn't find any information that proc_open doesn't work with safe_mode on...
mikeday
Hmm, proc_open() is not unsafe unless you pass arbitrary user input to it. But I guess they wanted to err on the side of caution. Did it give any error message indicating that safe_mode was the issue, or just fail silently?
spaff
No error were given, it just didn't work..

I tried your recommendation, to add the line "touch /tmp/prince.is.running", but prince.is.running wasn't created. Than I tried shell_execute to see if it works that way and than there came the error that shell_execute doesn't work with safe_mode on. I turned safe_mode off and tried it with proc_open again and it worked.