Solving HTML cover pages error in Avantfax

Today we had a coding marathon diving into the insights of the Avantfax-Hylafax relationship. It’s a dark relationship, but we managed to understand and find out the problem.

The problem

We have using Avantfax + HTML Cover pages with Ubuntu 8.04 and 10.04 server for a couple of years. We were very happy until cover pages stopped working. The user can submit a fax and the fax is sent without errors; but the cover page doesn’t arrive.

How to debug this problem

We love Ruby and we don’t love PHP so much, but there are too many applications using it :P. In order to debug the problem we tried using the “error_log” function, but, funny thing, it only worked in some of the files of Avantfax (we found out why later). A workaround was using this to understand the content of some variables:

system("echo 'patata HTML2PS filename: ".$HTML2PS." ".$filename."' >> /var/log/php.log");

Another tip: editing includes/functions.php you can see the parameters being sent to sendfax. If you run those in cli, it doesn’t work. Try to remove the “-S” parameter and the the verbose parameter “-vv”. This gives a lot of information about what sendfax is doing.

The cover page flow

  • Avantfax prepares the sendfax command (a long list of options including the cover page options from the Avantfax interface)
  • exec_sendfax in includes/functions.php calls to the Hylafax binary /usr/bin/sendfax.
  • Hylafax binary /usr/bin/sendfax calls includes/faxcover.php (based on the Hylafax config file)
  • includes/faxcover.php gives back a PS file through standard output
  • this PS file is saved in /tmp, and then copied to /var/spool/hylafax/docq folder.
  • The cover page and the rest of the pages are attached and sent.

Why did the cover page stop working?
After playing with cli, we found out that the PS documents in /var/spool/hylafax/docq were corrupted. A PS file normally starts with “%!PS” but the ones created by sendfax/faxcover.php started with a few lines of PHP warnings:

PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imagick.ini on line 1 in Unknown on line 0
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2.php on line 390
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2.php on line 1885
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2.php on line 2572
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2.php on line 2595
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2.php on line 2940
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2/Driver/mysql.php on line 924
PHP Deprecated:  Assigning the return value of new by reference is deprecated in /usr/share/php/MDB2/Driver/mysql.php on line 1190
%!PS

Sendfax is saving not only the standard output, but the error output too. That’s terrible.

When did the problem start?
A PHP update must have deprecated some functions :)

And the fix?
Edit /etc/php5/cli/php.ini and make sure the error_log is sent to the syslog or another file. By default it goes to the console error output.

I don’t know why but we also had to edit the comments in /etc/php5/cli/conf.d/imagick.ini and /etc/php5/cli/conf.d/mcrypt.ini, replacing “#” with “//”.

And that’s it!

Post a comment.