cancel
Showing results for 
Search instead for 
Did you mean: 

Session start and file uploads

LittleBlackDuck
Newbie
Posts: 5
Registered: ‎07-09-2007

Session start and file uploads

I keep getting intermittent errors when one of my pages tries to start a session, and I'm told by PN that it is because the /tmp space is full at the time the script starts to run. They are not willing to increase the space available to /tmp (no great surprise), and they are not willing to control the space (they're probably incapable of it, even though I was given the impression that it was down to 1 or 2 users causing the problem).
PN tells me to use my own web space instead of /tmp (they seem not to have spotted the session problem!). Very helpfully, they refuse to tell me how to do this. Can anyone help?
I have found that both settings can be set in the php.ini file, and I have tried using
session.save_path /temp
upload_tmp_dir /temp
as directives in it. I've placed this php.ini file in the "/" directory of my ccgi directory, with file permissions of "640", and I've created a subdirectory "temp" in that same directory. When I call session_save_path() after the session has been opened, it reports that the session save path is still /tmp.
Do I need to place other parameters in php.ini? Is php.ini being stored in the correct location? And do I need to do anything else in the script that calls session_start()?
Any help would be appreciated.
14 REPLIES 14
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: Session start and file uploads

The location you specify has to be the absolute path from the system root. Additionally use of an override php.ini containing only changed values means everything else will revert to default - which is probably not what you want.
You need to use a complete copy of php.ini which you will find in this post. More information about setting session.save_path is given in this topic.
David
LittleBlackDuck
Newbie
Posts: 5
Registered: ‎07-09-2007

Re: Session start and file uploads

Thanks for all this -- it's very helpful, and it works!
LittleBlackDuck
Newbie
Posts: 5
Registered: ‎07-09-2007

Re: Session start and file uploads

I THOUGHT it worked, but it hasn't! When I use phpinfo(), it reports the session.save_path to be /share/.../temp (the file at the top level of my cgi space), which looks as if it should work (and confirms that my /share/.../php.ini file is the Loaded Configuration File). However, I am still getting messages (eg Warning: session_start() [function.session-start]: open(/tmp/sess_6b5245b0ed4a2474537aa759dde1ace1, O_RDWR) failed: File too large (27)) that clearly state that session-start is trying to write to the system temporary file (/tmp).
I'm completely stumped. I've got my directory (.../temp) with permissions of #700, which (I think) should be right. Should they be different? Why is PHP saying that it will use my .../temp file, but then using the system /tmp file?
7up
Community Veteran
Posts: 15,445
Thanks: 1,236
Fixes: 14
Registered: ‎01-08-2007

Re: Session start and file uploads

IF you're using shared hosting no amount of editing your php.ini file will work because it will be in the php root directory - in other words the settings are set by PN web admin. You can't change that unfortunately unless they've got some fancy setup where you can have your own php.ini. Even then I presume Apache would need to be restarted before the settings would take effect.
I've never got permission 700 to do anything useful for me to be honest. The lowest I've ever used is 755 but I've been as daring as to go up to 777 in the past although thats not on PN servers which I've never used. Oddly though on my current hosting provider (and the last few) I've never even bothered with permissions. I thought they were only for perl scripts tbh as my php scripts can run with almost anything which is weird when you think that logically they should need permissions like any other process.
I need a new signature... i'm bored of the old one!
Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: Session start and file uploads

Hi LBD,
For permissions on ccgi, see the FAQ and links. Your folder will need to be 710. You would either need a copy of the ini file in each subdirectory containing php scripts or (better) a symlink. Or you could use something like this.
Gabe
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: Session start and file uploads

Quote from: okrzynska
IF you're using shared hosting no amount of editing your php.ini file will work because it will be in the php root directory - in other words the settings are set by PN web admin. You can't change that unfortunately...

This is not true, you can overwrite our values for most of the php.ini options using a php.ini file in the same directory that your script is in.
See http://uk2.php.net/manual/en/ini.list.php, anything which has PHP_INI_ALL or PHP_INI_PERDIR in the 'Changeable' column can be overwritten in this manner.
LittleBlackDuck
Newbie
Posts: 5
Registered: ‎07-09-2007

Re: Session start and file uploads

Hooray -- session_save_path() is at last reporting that it is using my temp file. That should save me from the problem of the system /tmp file running out of space (I hope!). Thanks to Gabe and Spraxyt for your help.
Putting it all together, in case it's of use to anyone else, I've ended up doing the following:
a) I copied the full php.ini file (see spraxyt's response) into my top ccgi directory, and also into the directory that contains my scripts (one of these should be a link to the other, rather than a copy, but I'll worry about that later).
b) I placed a short php file that contains the code <?php phpinfo(); ?> into my top cgi directory (eg as a file called phpinfo.php). I ran this by inserting its URL into a browser window, and this gave me a whole load of information about the php environment. I then checked what the full path name was to my cgi directory (where I intended to create a directory to hold my session information and any file uploads). Looking at the value of Loaded Configuration File in the phpinfo window, I took this path (for me, starting /share/storage/) as the full path name to my cgi space.
c) I created a directory (temp in my case) at the top of my cgi space, and gave it permissions of #710.
d) In both of the php.ini copies, I changed the value of upload_tmp_dir and session.save_path to the full path to my cgi space obtained from (b) plus the temp directory name eg if the full path to my cgi space was /share/storage/steve then the full path name used with the variables would be put in the php.ini files as
session.save_path = /share/storage/steve/temp
upload_tmp_dir = /share/storage/steve/temp
to replace the default directives.
e) If your scripts live in more than one directory, you need a copy of php.ini in each directory in which the scripts are held.
This now seems to work, in that I've got one of my scripts to report what the session save path is, and it reports that it is the one I've included in (both of) the php.ini files. No errors have occurred with running out of space.
Thanks again for your solution -- I would never have been able to find one without you!
7up
Community Veteran
Posts: 15,445
Thanks: 1,236
Fixes: 14
Registered: ‎01-08-2007

Re: Session start and file uploads

Quote from: Ben
Quote from: okrzynska
IF you're using shared hosting no amount of editing your php.ini file will work because it will be in the php root directory - in other words the settings are set by PN web admin. You can't change that unfortunately...

This is not true, you can overwrite our values for most of the php.ini options using a php.ini file in the same directory that your script is in.
See http://uk2.php.net/manual/en/ini.list.php, anything which has PHP_INI_ALL or PHP_INI_PERDIR in the 'Changeable' column can be overwritten in this manner.

I stand corrected! Thanks for the info Wink
I need a new signature... i'm bored of the old one!
EricKara
Newbie
Posts: 1
Registered: ‎29-01-2011

Re: Session start and file uploads

I was getting the same error message mentioned in this thread (File too large (27)). So, I have followed the instructions to create php.ini file and temp directory in my ccgi root directory.
The error messages disappeared now. However, I encountered a new problem.
The user pages that require UserID and password to login are now asking for re-login during the same session when moving from page to page. 
I checked and tried different permissions for the temp directory, I checked that the two paths, namely session.save_path and upload_tmp_dir are pointing to the correct temp file, but cannot solve this problem.
I am sure Iam missing some thing here.
I compared the original configuration settings from phpinfo.php with the new settings after the changes: everything is as before, except these two paths.
Any ideas?
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: Session start and file uploads

Have you got a php.ini file (or a link to the root one) in each directory where PHP files reside?
David
LittleBlackDuck
Newbie
Posts: 5
Registered: ‎07-09-2007

Re: Session start and file uploads

Quote from: EricKara
The user pages that require UserID and password to login are now asking for re-login during the same session when moving from page to page. 

Quote from: spraxyt
Have you got a php.ini file (or a link to the root one) in each directory where PHP files reside?

I have all my scrips in a single directory and there is no problem (once logged in, users stay logged in). but several people have mentioned that the php.ini file needs to be in each directory where you have your scripts. If that works for you, I'll try to amend my "solution".
oliverb
Grafter
Posts: 606
Registered: ‎02-08-2007

Re: Session start and file uploads

Think I'm having this problem trying to run an install script. I'll try the fix another day, right now in a fit of pique I deleted the whole lot, it'll have to wait.
FWIW I'm looking at a package called XOOPS, it seems popular on Sourceforge
Oh and if the ini file needs to be in EVERY folder then does anyone know the script-fu to search all folders and create a symlink in every one?
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: Session start and file uploads

This script adds a link to php.ini into each subdirectory. It also extracts the path to the session.save_path (note: the full path from the server root) from php.ini and ensures a link is not put into that subdirectory.
[code=linkphpini.cgi]
#!/bin/bash
echo -e -n "Content-type: text/plain\n\n"
currdir=`pwd`
if [ ! -e ./php.ini ] ; then
 echo "./php.ini file not found in $currdir"
 exit 1
fi
pipath="$currdir/php.ini"
sessdir=`awk -F "/" '/^[ \t]*session.save_path *=/ \
 { gsub(/[ \t\r\n]/,"",$NF); printf("%s", $NF) }' ./php.ini`
if [ -z "$sessdir" ] ; then
 echo "session save directory definition not found in ./php.ini"
 exit 2
fi
echo -e "adding links to '$pipath'\ninto directories other than './$sessdir'"
find . -mindepth 1 -type d \( -name "$sessdir" -prune -o -print \) | \
 while read i; do echo "  $i"; ln -s "$pipath" $i; done
echo "done"[/code]
Store this as, for instance, linkphpini.cgi in the same directory as php.ini. Set permissions to 0700 then run it in your browser. It will create a symlink to php.ini in each subdirectory (except the session directory).
Edit: first sentence revised.
David
Gabe
Community Veteran
Posts: 767
Registered: ‎29-10-2008

Re: Session start and file uploads

Only really need to put the link in folders containing php scripts (I think?). Something like this would do that.

#!/bin/bash
echo "Content-type: text/html"
echo
for file in $(find . -mindepth 1 -type d -print0 | xargs -0)
do
[[ $(ls "$file") =~ \.php ]] && ln -s "$(pwd)/php.ini" "$file/php.ini" && echo "$file/php.ini<br>"
done

(again set 0700 and call in browser)
TBH, that's not what I actually do. I use a wrapper to bring the scripts to the ini. It looks more complicated but seems to cut down on maintenance.
Gabe