Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 94cc5af

Browse files
committedDec 2, 2023
swoole in cygwin: improved getBaseDir() to work better even with the version of Swoole that does not have SCRIPT_DIR
1 parent 9ce0eee commit 94cc5af

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed
 

‎src/crawler.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@
8686
function getBaseDir(): string
8787
{
8888
if (stripos(PHP_OS, 'CYGWIN') !== false) {
89-
return rtrim(platformCompatiblePath($_SERVER['SCRIPT_DIR'], '/'), '/ ');
89+
if (isset($_SERVER['SCRIPT_DIR']) && $_SERVER['SCRIPT_DIR'] && preg_match(':\/', $_SERVER['SCRIPT_DIR']) === 1) {
90+
return rtrim(platformCompatiblePath($_SERVER['SCRIPT_DIR']), '/ ');
91+
} else {
92+
return dirname(platformCompatiblePath($_SERVER['SCRIPT_FILENAME']), 2);
93+
}
9094
} else {
9195
$scriptRealPath = str_starts_with($_SERVER['SCRIPT_FILENAME'], '/') ? $_SERVER['SCRIPT_FILENAME'] : realpath($_SERVER['SCRIPT_FILENAME']);
9296
return dirname(platformCompatiblePath($scriptRealPath), 2);

0 commit comments

Comments
 (0)
Please sign in to comment.