A Permission denied Notice solution encountered by the PHP Session, permissionnotice
If PHP installed with apt is used in ubuntu/Debian, this prompt may be reported when Session is used.
Copy codeThe Code is as follows:
PHP Notice: session_start (): ps_files_cleanup_dir:
Opendir (/var/lib/php5) failed: Permission denied (13)
In/home/laruence/www/htdocs/index. php on line 22
This is because, in PHP, if file_handler is used as the save handler of the Session, the Gc process of the Session will be run at each session_start.
Copy codeThe Code is as follows:
// Omitted
Int nrdels =-1;
Nrand = (int) (float) PS (gc_divisor) * php_combined_lcg (TSRMLS_C ));
If (nrand <PS (gc_probability )){
PS (mod)-> s_gc (& PS (mod_data), PS (gc_maxlifetime), & nrdels TSRMLS_CC );
}
// Omitted
The cause of this warning is that in apt PHP, the default session directory/var/lib/php5 has the permission of 733 with sticky bit, that is
Copy codeThe Code is as follows: drwx-wx-wt root
Generally, PHP worker runs in a non-root identity, so it does not have the permission to open this folder (but because it can be written, it does not affect normal Session file reading ). the following code in s_gc triggers the Notice mentioned at the beginning:
Copy codeThe Code is as follows:
// For file handler, s_gc indirectly calls ps_files_cleanup_dir:
Dir = opendir (dirname );
If (! Dir ){
Php_error_docref (NULL TSRMLS_CC, E_NOTICE,
"Ps_files_cleanup_dir: opendir (% s) failed: % s (% d )",
Dirname, strerror (errno), errno );
Return (0 );
}
Of course, gc is still available in ubuntu/Debian, but it is completed by external cron processes. The default value is/etc/cron. d/php5 :,
Copy codeThe Code is as follows:
* 39 * root [-x/usr/lib/php5/maxlifetime]
& [-D/var/lib/php5] & find/var/lib/php5/
-Type f-cmin + $(/usr/lib/php5/maxlifetime)-print0
| Xargs-n 200-r-0 rm
In addition, we can see that when determining whether s_gc is running, there are two key variables: PS (gc_divisor) and PS (gc_probability ), these two variables correspond to the two same-name configuration items of the session runtime configuration item respectively:
Session. gc_probability and session. gc_divisor. The default values are 1 and 100, respectively.
Php_combined_lcg is a random number generator that generates a random number ranging from 0 to 1. Therefore, the above discrimination is equivalent:
Copy codeThe Code is as follows:
Rand <probability/gc_divisor
That is to say, by default, the gc process can be called almost 100 times. Therefore, the Notice can be seen at a low probability.
To disable this Notice, you only need to set:
Session. gc_probability = 0, so that s_gc has no possibility of running.
Of course, you can also change the permissions of this folder...
Php session Permissions
The session storage path C: \ WINDOWS \ TEMP \ does not have the development write permission to the web User
This means that you have no permissions. You cannot use session_start to create a session.
Why does the Server Report the session_start () Permission denied (13) error?
This error appears because the directory where the session file is stored does not have the write permission to apache users. To solve this problem, you only need to set the php configuration file php. session in ini. set save_path to the temporary directory, for example, session. save_path = "/tmp/php5" Save php. ini and then restart apache to take effect. Go to the website of the website construction technology learning forum to view the answer details>