phpcentosinfinite-loopphpdocphpdocumentor2

Infinite loop with PHPDocumentor when invoked from CLI (but fine via SSH)


Up to yesterday, I used, on our production server (CentOS 6.8), PHPDocumentor version 2.8.5. and everything worked fine. I had to upgrade to version 2.9.0. since PHPDoc failed to generate the documentation for PHP7.

When I run the following script via SSH, everything works fine:

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/gem-mechanic/ --target=/[not_a_real_path]/PC_administration_interface/documentation/gem-mechanic/ --title="GEM-MECHANIC"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/PC_administration_interface/ --target=/[not_a_real_path]/PC_administration_interface/documentation/pc_administration_interface/ --title="PC-ADMINISTRATION-INTERFACE"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/setup/modules/appointmentmanager/ --target=/[not_a_real_path]/PC_administration_interface/documentation/prestashop_appointmentmanager/ --title="PRESTASHOP: APPOINTMENT MANAGER"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/setup/modules/datalinkmanager/ --target=/[not_a_real_path]/PC_administration_interface/documentation/prestashop_datalinkmanager/ --title="PRESTASHOP: DATALINK MANAGER"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/setup/modules/sharedcode/ --target=/[not_a_real_path]/PC_administration_interface/documentation/prestashop_sharedcode/ --title="PRESTASHOP: SHARED CODE"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/setup/modules/vehiclefile/ --target=/[not_a_real_path]/PC_administration_interface/documentation/prestashop_vehiclefile/ --title="PRESTASHOP: VEHICLE FILE"

/[not_a_real_path]/phpdoc --directory=/[not_a_real_path]/shared_code/ --target=/[not_a_real_path]/PC_administration_interface/documentation/shared_code/ --title="SHARED CODE"

echo Options All -Indexes > /[not_a_real_path]/PC_administration_interface/documentation/.htaccess
echo AuthType Basic >> /[not_a_real_path]/PC_administration_interface/documentation/.htaccess
echo AuthName '"Please login"' >> /[not_a_real_path]/PC_administration_interface/documentation/.htaccess
echo AuthUserFile /[not_a_real_path]/PC_administration_interface/.htpasswd >> /[not_a_real_path]/PC_administration_interface/documentation/.htaccess
echo Require valid-user >> /[not_a_real_path]/PC_administration_interface/documentation/.htaccess

enter image description here

But, when I try to run the script with PHP

public static function generateDocumentation() 
{
    $output = array();

    set_time_limit(180);

    self::createDocDirectory();

    exec(self::getScriptPath(false) . " 2>&1", $output);

    return implode($output, PHP_EOL);
}

The coding gets stuck in an infinite loop, not generating any documentation. I would expect the page to fails after 3 minutes, but it just keeps looping...

Even trying to execute PHPDocumentor, it gets stuck in an infinite loop:

exec("[not_the_real_path]/phpdoc 2>&1", $output);

Is anyone has experienced a similar problem?


Solution

  • I took me two days of hard work, but I finally found out the source of the problem.

    1. phpDocumentor.phar requires calling PHP command before being executed.

    2. If the PHP command is not in your included path, you'll need to supply the full path.

    Somehow, if one of those to command isn't found, the CLI simply hangs.

    Here's an example of a valid command:

    exec("/usr/local/bin/php /usr/local/bin/phpDocumentor-2.9.phar --directory=/home/gem/public_html/gem-mechanic/ --target=/home/gem/public_html/PC_administration_interface/documentation/gem-mechanic/ --title=\"GEM-MECHANIC\" 2>&1", $output);
    

    Note: adding the following code line:

    PATH="/usr/local/bin"
    

    at the begining of your script, you won't need to call for PHP and include the path to reach phpDocumentor. A line in your script could be simply written as such:

    phpDocumentor-2.9.phar --directory=/home/gem/public_html/gem-mechanic/ --target=/home/gem/public_html/PC_administration_interface/documentation/gem-mechanic/ --title="GEM-MECHANIC"