views:

33

answers:

1

Hi,

Posted a question about an error I was getting the over day about Memory exceed when handling an image resize.

Managed to solve the problem with a local php.ini file and setting

[PHP]
upload_max_filesize = 5M
post_max_size = 5M
memory_limit = 64M

Now I realised I have a whole new problem :)

If I access a php file in the directoy with my custom local php.ini, it will override the original and remove all my $_SESSION's

If I remove the local php.ini, it doesnt remove my sessions but then the image resize gives me a memory limit exceed error.

Any ideas? Can i set a php.ini (local) to just override the 3 parameters I want?

Thanks in advance,

P.s. tried setting it through CPANEL on tweak php.ini but those values seemed to be ignored.


Result

Had to contact tech support and they had to manually update my ini files.

+2  A: 

If you have full control over your server, on most linux distros there is a conf.d directory which is loaded after all of the default php configuration, so you can override things. On ubuntu for example, that is /etc/php5/conf.d/, there you can create a file 'my.ini' (name doesn't matter as long as it ends in .ini) which will be automatically included.

If you don't have access to the entire server, there are several ways of altering those without overwriting everything:

  • Add the php configuration to .htaccess (if using Apache)
  • Set those options using ini_set('option', 'value'); in your php script

If you're going for the .htaccess route, here is an example, just append to end of your .htaccess file:

php_value upload_max_filesize 5M
php_value post_max_size 5M
php_value memory_limit 64M
Andrei Serdeliuc
Yea i cant find conf.d but the htaccess route is giving me Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.
Stevanicus
there is a php folder with data and ext and empty directories
Stevanicus
have you got access to the Apache error logs? Is there anything useful in there? Also, that won't work if PHP is not loaded as an apache module (if for example, your site is served via CGI)
Andrei Serdeliuc
thanks for your help btw, this is what the logs say /.htaccess: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration
Stevanicus
PHP might be dispatched via CGI then. If you can get in contact with your hosting provider, they should probably be able to help you out with altering the configuration just for your account. Otherwise, if your app has only one entry point (index.php, or an init file), you can add those 3 using `ini_set`
Andrei Serdeliuc
I've been in contact with my provider and they are unable to change the global ini file for me (as im on shared). They also say that htaccess way doesnt work as it is not mounted as a module. The local php ini is the only way. But I lose session ids with a local php.ini... p.s. the ini_set doesnt override the php.ini btw. Very strange. Any further ideas?
Stevanicus
Then you've got 2 options: Set the php options inside your main script (using `ini_set`), or inside the php.ini file configure everything you need to configure (including session save paths, etc ... this will take a while but it might be worth it in the long run?)
Andrei Serdeliuc
The thing is, a local php-ini works fine. so a global one i.e. in the root file should work to, however the sub directories dont recognise it. i.e. its still 32m instead of my 64. do you know a link to create a simple ini file, i've never really done it.
Stevanicus
also the ini_set dont override the default :S
Stevanicus
Andrei, I tried creating an entire php file, including all save paths etc. no luck I'm afraid. :(
Stevanicus