Forum How do I...?

PHP Version 7?

jimbrooking
Hi Mike,

On my Joomla website we recently changed our server settings to use PHP version 7.1.6. Our website is noticeably quicker on every page. Tried generating a report using Prince version 9 today and it failed in the PHP wrapper prince.php. Checking your site I see that Prince version 11 is available, but the Prince PHP wrapper title is still for PHP version 5. Have you any plans to generate a PHP version 7 version of the wrapper? Should the PHP v.5 wrapper work on PHP v.7?

Thanks.
mikeday
How did it fail? Did you receive any errors or warning messages?
jimbrooking
I am trying to figure out why it's failing. When I instantiate prince (11) and call convert_file() using the same code I used to call prince (9), the function returns false but no error messages are produced, which makes debugging challenging. It doesn't look like the convert_file() calling arguments are different between v9 and v11, unless I have missed something. I am trying to back-track the preparation for the calling of prince and convert_file() but not seeing anything. Let me delve a bit deeper and see if I can come up with anyhting sensible.
mikeday
Perhaps PHP 7 changes the behaviour of proc_open. If you use the setLog method to specify a Prince log file in a writable location (eg. /tmp/prince.log) does the file get created and contain any text?
jimbrooking
OK, I'm getting cross-eyed looking at this, so leaving it for tonight (NC USA - 9:14pm). Here's that I know:

With Prince 9:
Works with server running PHP 5.6
When change to PHP 7, gets an error message
Fatal error: Uncaught Error: [] operator not supported for strings in /home/fearrin1/public_html/code/prince-php/prince.php:715 Stack trace: #0 /home/fearrin1/public_html/code/prince-php/prince.php(585): Prince->readMessages(Resource id #21, '') #1 /home/fearrin1/public_html/code/prince-php/prince.php(346): Prince->convert_internal_file_to_file('/home/fearrin1/...', '') #2 /home/fearrin1/public_html/code/pdfit.php(51): Prince->convert_file('/home/fearrin1/...', '') #3 /home/fearrin1/public_html/fhaphp/nlDistribPDF2.php(79): pdfit() #4 {main} thrown in /home/fearrin1/public_html/code/prince-php/prince.php on line 715

which is in this function
   private function readMessages($pipe, &$msgs)
    {
	while (!feof($pipe))
	{
	    $line = fgets($pipe);
	    
	    if ($line != false)
	    {
		$msgtag = substr($line, 0, 4);
		$msgbody = rtrim(substr($line, 4));
		
		if ($msgtag == 'fin|')
		{
		    return $msgbody;
		}
		else if ($msgtag == 'msg|')
		{
		    $msg = explode('|', $msgbody, 4);

		    // $msg[0] = 'err' | 'wrn' | 'inf'
		    // $msg[1] = filename / line number
		    // $msg[2] = message text, trailing newline stripped

		    $msgs[] = $msg;
		}
		else
		{
		    // ignore other messages
		}
	    }
	}
	
	return '';
    }

at the line that says "$msgs[] = $msg;".

The XHTML file presented for conversion is correct to the extent that Prince (11) processes it correctly on mky desktop (Win7).

I've declared a Prince log file but it's not showing and activity (ever).
mikeday
Are you passing a value for the $msgs parameter to the convert method?
jimbrooking
Yes
        $princeMsgs = '';
        $pcvar = $prince->convert_file($outDest, $princeMsgs);
jimbrooking
Hah! I deleted the $princeMsgs = ''; statement and it worked!!!
mikeday
Right! It needs to be an array, not a list. I guess PHP 5 silently converted it, perhaps.
jimbrooking
Hi Mike, back again. Everything working OK with Prince v9. I changed the PHP wrapper from v9 to v11 and am getting a failure (FALSE) back from convert_file() with no error messages returned and no entries at all in the prince_error.log file. Prince v9 provides logging as expected bracketed by ---- begin and ---- end. Have there been changes in setup or calling parameters between v9 and v11?
  1. nl_distrib_order278380.xhtml29.4 kB
    File passed to Prince to convert
mikeday
Wait I'm confused, I thought it was working after changing the $princeMsgs?
jimbrooking
Well, that was Prince v9, which stopped working when I changed the site for PHP v7. I am now trying to upgrade from Prince v9 to v11 (also using PHP v7).
mikeday
Ah right sorry just a little slow on the uptake. :)

Can you try using the latest PHP wrapper?
jimbrooking
I have been trying to use the latest wrapper with Prince v11. But having rouble, possibly of my own doing. I am trying to change the interface to Prince to incorporate a version no., so I can easily change between prince9 and prince11 - changing the name "prince" to "princeX" (X=version). The renaming is done 1) in the wrapper on the website, 2) in the script that runs Prince in /usr on the server, and 3) in /usr/lib/bin on the server. Not having a lot of luck with this, or maybe internally "prince" without a version number is required?.
mikeday
I would start by installing two versions of Prince in different locations and checking that it works by running "/full/path/to/prince --version" from the command-line, first.
jimbrooking
Unfortunately I don't have a command-line access.
mikeday
Okay that makes it slightly more tricky. The "prince" script installed in /usr/bin by default will be trying to exec the Prince binary, so renaming files may require editing this script.
jimbrooking
OK, I created a file named prince11 un the /usr directory, And edited it to read
#! /bin/sh
echo called >> /tmp/prince.log
PROGRAM="prince11"
prefix=/home/fearrin1/usr
export LD_LIBRARY_PATH="/home/fearrin1/usr/lib/giflib/giflib"
exec $prefix/lib/$PROGRAM/bin/$PROGRAM --prefix="$prefix/lib/$PROGRAM" "$@"

and I think I have renamed the program file in /usr/lib/bin to prince11 and the directory in /usr as prince11, wherein the "Generic Linux" files are stored. (The OS on the server is CentOS.)
mikeday
That looks good, just make sure it has execute permissions.
jimbrooking
Thank you Sir! It's the simplest stuff (like execute permissions) that trips me up. My symptoms have changed, and I think I can work it out tomorrow (it's quite late here in the eastern USA). Thanks for your help, as always.
mikeday
Best of luck! :D