Skip to content

fix: correct WSDL URL construction in ilSoapClient for ILIAS 10#11214

Draft
sKarki999 wants to merge 1 commit intoILIAS-eLearning:release_10from
sKarki999:fix/release_10_42320
Draft

fix: correct WSDL URL construction in ilSoapClient for ILIAS 10#11214
sKarki999 wants to merge 1 commit intoILIAS-eLearning:release_10from
sKarki999:fix/release_10_42320

Conversation

@sKarki999
Copy link
Contributor

@sKarki999 sKarki999 commented Mar 1, 2026

Comment on lines +109 to +130
$i = 0;
if (PHP_SAPI !== 'cli') {
$script_path = dirname($_SERVER['SCRIPT_FILENAME']);
while (!is_file($script_path . '/ilias.php') && $i < self::MAX_DIRECTORY_SEARCH_DEPTH) {
$script_path = dirname($script_path);
$i++;
}
}

if ($i > 0 && is_file($script_path . '/ilias.php')) {
$url_parts = parse_url($request_path);
$path = $url_parts['path'] ?? '';
$path_parts = explode('/', rtrim($path, '/'));
$path_parts = array_slice($path_parts, 0, count($path_parts) - $i);
$new_path = implode('/', $path_parts);

$request_path = $url_parts['scheme'] . '://' . $url_parts['host'];
if (isset($url_parts['port'])) {
$request_path .= ':' . $url_parts['port'];
}
$request_path .= $new_path;
}
Copy link
Contributor

@mjansenDatabay mjansenDatabay Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Saghun,

this seems to work, but isn't it sufficient to do this instead?

$request_path = ilUtil::_getHttpPath();
if (PHP_SAPI !== 'cli') {
    $i = 0;
    $script_path = dirname($_SERVER['SCRIPT_FILENAME']);
    while (!is_file($script_path . '/ilias.php') && $i < 20) {
        $script_path = dirname($script_path);
        $i++;
    }

    if ($i > 0 && is_file($script_path . '/ilias.php')) {
        $request_path = dirname($request_path, $i);
    }
}

echo $request_path . '/soap/server.php?wsdl';

My local installation is running on http://localhost.php8-3/ilias/10x and it works fine. Can you provide any $_SERVER['SCRIPT_FILENAME'] or value returned by the $request_path = ilUtil::_getHttpPath() call which does not work with my snipped above?

Best regards,
Michael

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mjansenDatabay ,

With only those changes i am receving this in the log:
[935cf] [2026-03-02 11:19:23.091395] atlas10_wsrv.WARNING: ilSoapUtils::callNextNode:178 Soap init failed with message: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http:/soap/server.php?wsdl' : failed to load external entity "http:/soap/server.php?wsdl".

The path is not formed correctly in my system. So instead of dirname, I parsed the URL to reconstruct the base URL and appending /soap/server.php?wsdl, and it works.
Additionally my local instance is simply: "http://localhost" so value returned by $request_path = ilUtil::_getHttpPath() is 'http://localhost'.

For example:
For something like this:
dirname("http://localhost", 1) => it returns "http:". The host is getting stripped, producing "http:/soap/server.php?wsdl"

Am i missing something here? Please let me know, what do you think? :)

kind regards,
Sagun

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Sagun,

thanks for the feedback.

What I do not understand: In case the HTTP client requests http://localhost/ilias.php, ilUtil::_getHttpPath() seems to return http://localhost in your case, $_SERVER['SCRIPT_FILENAME'] should then point to something like this: `/var/www/your_ilias_root/public/ilias.php.

In case the HTTP client requests http://localhost/soap/server.php. ilUtil::_getHttpPath() should return http://localhost/soap and $_SERVER['SCRIPT_FILENAME'] should point to something like this: /var/www/your_ilias_root/public/soap/server.php.

In both cases, the code snippet above should work.

Best regards,
Michael

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mjansenDatabay ,

With only those changes in my system i receive following.
I have added few logs and triggered the copy process.

In the logs i can see such statements.
DEBUG _getHttpPath() returns: http://localhost
DEBUG ILIAS_HTTP_PATH constant: http://localhost
DEBUG ILIAS_MODULE: components/ILIAS/soap
DEBUG SCRIPT_FILENAME: .../public/soap/server.php
And:

DEBUG request_path: http://localhost <--- before dirname($request_path, 1)
DEBUG SCRIPT_FILENAME: .../public/soap/server.php
DEBUG request_path: http: <--- after dirname($request_path, 1)
DEBUG SCRIPT_FILENAME: .../public/soap/server.php
atlas10_wsrv.WARNING: Soap init failed with message: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http:/soap/server.php wsdl' : failed to load external entity "http:/soap/server.php?wsdl"

Any clue why this is happening in my system or somewhere i can check for the settings which might be different than how you have in your system or in general.
Thanks in advance :)

kind regards,
Sagun

Copy link
Contributor

@mjansenDatabay mjansenDatabay Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay, SCRIPT_FILENAME must be an absolute server path if executed in a "Web Context".

Do you execute/test the snippet with PHP CLI (which actually cannot be the case, since there is a PHP_SAPI !== 'cli' check)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bildschirmfoto vom 2026-03-03 14-28-13

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mjansenDatabay

Till now, i executed in web context. I triggered the copy from the UI and hence the information in logs.

:)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, maybe some misconfiguration? That's unexpected under normal PHP behavior and likely indicates a server configuration issue (e.g., FPM backend not setting expected vars) or the request being proxied incorrectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi again @mjansenDatabay ,

Please correct me if i am wrong here.
I tested directly in HttpPathBuilder.
When I access http://localhost/soap/test.php, REQUEST_URI is /soap/test.php and _getHttpPath() returns http://localhost/soap. So the test script would work correctly with dirname.

However, one thing i noticed, the soap/server.php defines ILIAS_MODULE = 'components/ILIAS/soap'. When this constant is defined, HttpPathBuilder::build() strips the module depth from REQUEST_URI, so perhaps _getHttpPath() returns just http://localhost.

With that, dirname("http://localhost", 1) strips the host instead of a path segment, producing "http:".

Maybe this behaviour is due to the fact in the files test script and soap/server.php, only server.php defines ILIAS_MODULE. Could this be the case?

What should be done at this point as we are undecided only about one part? What do you recommend here?

Thank you :)
Sagun

@mjansenDatabay mjansenDatabay added bugfix php Pull requests that update Php code labels Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants