简体   繁体   中英

why session_start in php is throwing warning saying file large

I didn't change any code, all of a sudden when I visited one of the webpages, I see

Warning: session_start() [function.session-start]: open(..)Failed: File too large .. index.php on line 2.

Another error is:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent`

Line1 : <?php

Line2 : session_start ();

Questions :

  1. what is the reason for error that tells File too large? what file is large?

  2. why all-of a sudden there is an error without any file modification being done?

  3. why it is throwing 'headers already sent', when there is nothing defined before session_start , not even a space ?

  4. How to fix this issue?

1. what is the reason for error that tells File too large? what file is large?

  • This seems to be the hosting provider issue, as the original file was never modified, and the webpage has been tried from multiple browsers even after clearing the cache. When you do session_save_path("../_session1001"); that is mentioned below, you can see that your session is written to that path, so may be that this file was becoming too large in your shared memory,and now that I explicitly mentioned a physical space to write the session files to, this error is no more.

4. How to fix this issue?

  • Create a directory named say '_session1001' and give chmod 755 so your webserver (app) can write to it.
  • Add this line before session_start session_save_path("../_session1001");
  • Ensure you protect the directory via .htaccess file.

ie: <?php session_save_path("../_session1001"); session_start(); <?php session_save_path("../_session1001"); session_start();

Read more here : http://php.net/session_save_path

Note:

Debian does not use the default garbage collector for sessions. Instead, it sets session.gc_probability to zero and it runs a cron job to clean up old session data in the default directory.

As a result, if your site sets a custom location with session_save_path() you also need to set a value for session.gc_probability ,

eg:

<?php session_save_path('/home/example.com/sessions'); ini_set('session.gc_probability', 1); ?>

Otherwise, old files in '/home/example.com/sessions' will never get removed!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM