console-parallelization icon indicating copy to clipboard operation
console-parallelization copied to clipboard

Error when the server script name is an absolute path

Open theofidry opened this issue 2 years ago • 4 comments

With the current code:

$pwd = $_SERVER['PWD'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        return str_starts_with($scriptName, $pwd)
            ? $scriptName
            : $pwd.DIRECTORY_SEPARATOR.$scriptName;

If the script name is absolute, e.g. /usr/local/bin/box, the resolved script name will be a nonsensical path.

theofidry avatar Nov 11 '23 19:11 theofidry

I'm a pimcore user where this library is used e.g. to run the console commands for data-importer. Using that functionality I ran in exactly this issue with data import cron job which has absolute path for the script set. For me, running a Linux server, the following change did solve the issue (will be different for e.g. Windows):

    private static function getScriptPath(): string
    {
        $pwd = $_SERVER['PWD'];
        $scriptName = $_SERVER['SCRIPT_NAME'];

        return (str_starts_with($scriptName, $pwd)
                || str_starts_with($scriptName, DIRECTORY_SEPARATOR))
            ? $scriptName
            : $pwd.DIRECTORY_SEPARATOR.$scriptName;
    }

APochmann avatar Feb 16 '24 12:02 APochmann

@APochmann would you be open to do a PR with this patch?

theofidry avatar Feb 18 '24 17:02 theofidry

Sure, but I do not have possibility to test on Windows system, tested only on my Linux system

APochmann avatar Feb 19 '24 08:02 APochmann

That is ok, we don't own a windows machine either so this library has never really been tested on Windows. This could probably be done now by adding a Windows job to the pipeline since GA supports Windows, if someone wants to work on this

theofidry avatar Feb 20 '24 08:02 theofidry