Hi.
I've been playing with the session.save_path=n;path setting.
The documentation says that there is a mod_files.sh file to help
create the folder structure (which there is).
But this won't run natively on windows.
I've attached this patch below to create a windows variant
(mod_files.bat) which works quite nicely.
If someone can be nice enough to add it, I'll amend the docs to
reflect the windows variant.
If anyone actually reads it you'll notice that only upper case letters
are used for the directory names. Windows is case insensitive and as
such a === A with regards to file and folders.
Regards,
Richard Quadling.
--- mod_files.bat
+++ mod_files.bat
@@ -0,0 +1,57 @@
+@ECHO OFF
+SETLOCAL ENABLEDELAYEDEXPANSION
+IF %1==AUTO (
- GOTO MakeDirs
+)
+IF %2==__ (
- ECHO Usage %0 ^<basedir^> ^<depth^> ^[^hash_bits^]
- ECHO.
- ECHO Where ^<basedir^> is the session directory
- ECHO ^<depth^> is the number of levels defined in session.save_path
- ECHO ^[hash_bits^] is the number of bits defined in
session.hash_bits_per_character - EXIT /B 1
+)
+SET /A Depth=%2 + 0 2>NUL
+IF /I %ERRORLEVEL% EQU 9167 GOTO DepthError
+IF %Depth%==__ GOTO DepthError
+IF /I %Depth% LEQ 0 GOTO DepthError
+IF %3==__ GOTO DefaultBits
+SET /A Bits=%3 + 0 2>NUL
+IF /I %ERRORLEVEL% EQU 9167 GOTO BitsError
+IF %Bits%==__ GOTO BitsError
+IF /I %Bits% LSS 4 GOTO BitsError
+IF /I %Bits% GTR 6 GOTO BitsError
+GOTO BitsSet
+:DefaultBits
+SET Bits=4
+:BitsSet
+SET HashChars=0 1 2 3 4 5 6 7 8 9 A B C D E F
+IF /I %Bits% GEQ 5 SET HashChars=!HashChars! G H I J K L M N O P Q R S T U V
+IF /I %Bits% GEQ 6 SET HashChars=!HashChars! W X Y Z - ,
+FOR %%A IN (%HashChars%) DO (
- ECHO Making %%A
- CALL "%~0" AUTO "%~1%%~A" %Depth%
+)
+GOTO :EOF
+:MakeDirs
+MKDIR "%~2"
+SET /A ThisDepth=%3 - 1
+IF /I %ThisDepth% GTR 0 FOR %%A IN (%HashChars%) DO CALL "%~0" AUTO
"%~2%%~A" %ThisDepth%
+GOTO :EOF
+:DepthError
+ECHO ERROR: Invalid depth : %2
+EXIT /B 0
+:BitsError
+ECHO ERROR: Invalid hash_bits : %3
+EXIT /B 0
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
I've been playing with the session.save_path=n;path setting.
The documentation says that there is a mod_files.sh file to help
create the folder structure (which there is).But this won't run natively on windows.
I've attached this patch below to create a windows variant
(mod_files.bat) which works quite nicely.
Can't we use a platform independent PHP version? I assume that PHP
should be installed when using PHP sessions (yeah one might have the
server module -> own fault)
johannes
2008/12/11 Johannes Schlüter johannes@php.net:
I've been playing with the session.save_path=n;path setting.
The documentation says that there is a mod_files.sh file to help
create the folder structure (which there is).But this won't run natively on windows.
I've attached this patch below to create a windows variant
(mod_files.bat) which works quite nicely.Can't we use a platform independent PHP version? I assume that PHP
should be installed when using PHP sessions (yeah one might have the
server module -> own fault)johannes
I suppose there would be a performance hit if the core dealt with it?
I would guess that in php-src/ext/session/mod_files.c, a ...
mkdir(buf);
between lines 117 and 118 ...
for (i = 0; i < (int)data->dirdepth; i++) {
buf[n++] = *p++;
buf[n++] = PHP_DIR_SEPARATOR;
}
mkdir(buf);
memcpy(buf + n, FILE_PREFIX, sizeof(FILE_PREFIX) - 1);
n += sizeof(FILE_PREFIX) - 1;
should theoretically fix the problem. It only needs to create the
folders if it doesn't exist, but mkdir()
won't result in a crash if
the directory already exists.
I don't know if mkdir()
is recursive, adding a few more mkdir()
's
(before and during the for() loop, should fix that.
Of course, being able to call PHP's internal version of mkdir(buf,
0x777, true); would be ideal.
I've attached a patch to for both the .BAT and .PHP versions.
The PHP version doesn't require any parameters simply because it can
easily read the INI file.
I suppose doing some checking to make sure the Depth doesn't exceed
the number of available characters (depending upon the hash algorithm
and the SESS prefix, etc. would be more complete, but ...
Richard.
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"