Tuesday 18 August 2009

Setting Per site php.ini

Sometimes when I start my PC, the Desktop resolution has been adjusted to 1600x1200, which is quite random, and annoying as I have to change the resolution back to 1280x960. So I decided to have a quick Google and see if I could find a solution to this.

I found a thread about Dell laptops reverting back to a lower resolution on hibernation/restart: Screen resolution changes on restart/hibernation, so a slightly different problem to mine, but along the same lines in that the resolution changes.

There was an answer in the thread, and everyone who tried it said it worked:
Open Task Scheduler ( All Programs/Accessories/System Tools/Task Scheduler)

Then go to "Task Scheduler Library/Microsoft/Windows/MobilePC" .

Then disabled "TMM"

So I tried disabling that. Whether it will work or not, I'm not sure, since my problem is slightly different to one posted there.

After that I tried to get one of my websites to redirect from domain.com to www.domain.com. When the site was running on Apache, I had done this by adding the following to a .htaccess file located in the site root:
RewriteEngine On

RewriteCond %{HTTP_HOST} ^milkcapmania\.com$ [NC]
RewriteRule ^(.*)$ http://www.milkcapmania.com/$1 [R=301,QSA,L]

In NginX, you can't use .htaccess files, so the rewrite rules must go in the site config:
server {
listen 80;
server_name www.domain.com domain.com;

location / {
index index.html;
root /my/site/root;

#rewrite to www.
if ($host ~ ^domain.com$) {
rewrite ^(.*)$ http://www.domain.com$1 permanent;
}
}

#Other site config stuff here
}

Or, probably a better way to do it would be to separate the www. sub domain and base domain into separate configs, then the rewrite rule won't have to be checked when a user is browsing the www. subdomain:
server {
listen 80;
server_name domain.com;
#rewrite to www.
rewrite ^(.*)$ http://www.domain.com$1 permanent;
}

server {
listen 80;
server_name www.domain.com;

location / {
index index.html;
root /my/site/root;
}

#Other site config stuff here
}


Next I was trying to see how I could set different php.ini values for each of my sites. With PHP running under Apache, you can use
php_value php.ini_property = value
Or
php_flag php.ini_property = value
in an .htaccess file.

When running PHP through suPHP or php_suexec, you can use a php.ini file (which you must place in each directory you want it to take effect).

With running PHP through spawn-fcgi, I have seen some threads suggesting running a different PHP process for each site you want a different php.ini file for, passing the -c option to spawn-fcgi with the location of the php.ini file you want loaded. Each process with a different php.ini file would need to have it's own port/socket as well. Then in the site config, you fcgi_pass to the correct php process. This thread shows how to do it: Alternative php.ini for a subdomain on Nginx.

However, the problem with this is that you need to run more php processes, and if a site suddenly gets heavy traffic, it will only be able to use that php processes that you've set the site to use. e.g. If I have 5 sites, and run 5 php processes, if one site gets heavy traffic, then normally that traffic would be shared between the 5 processes. However, if I'm running a different php.ini for each process (and so running each process on a different port/socket), and run 1 process for each site (so 5 processes in total again), then if one site gets some heavy traffic, your one php process won't be able to cope. You could run 5 processes per site (so 25 processes total), but you'd need lots of memory for that.

Luckily php5.3 has
".htaccess" style user-defined php.ini files support for CGI/FastCGI
I found a page that described this change in a bit more detail: What is new in PHP 5.3 - part 4: __callStatic, OpenID support, user.ini, XSLT profiling and more. However, try as I might, I couldn't get the options I added in my user.ini file to show that they were in effect in a phpinfo() page.

Then I noticed in the phpinfo() page, the user_ini.filename value was .user.ini (note the dot before the filename). Actually, this is pretty obvious on the PHP Manual page for .user.ini files, which I had read, though somehow I hadn't noticed the dot before the filename.

So now I can set a different include_path php.ini directive for each of my sites.

In the afternoon I did a bit more website stuff, played on Animal Crossing, and looked into some computer stuff someone had emailed me about.

After dinner I finished looking into the computer issues, and also watched a video by the next famous youtube person, who is a kid who mimes along to songs in the New York Apple store - quite funny seeing what all the people in the background do, and the kid doesn't get put off by them at all - nicholifavs: viking remix dat new new part 4.

Also, when looking into the computer stuff, the person who emailed me wanted to view a flash video (.swf format, not .flv). On my PC, I can just double click a .swf file, and it will open in Adobe Flash Player. However, I couldn't find a download for a standalone player on Adobe's website, just the browser plugins. Googling for Standalone Flash player, I found this blog post: Stand alone flash player, which explains how to download a stand alone Flash player.

However, it's a standalone executable, so you don't even need to install it. This means that it doesn't associate the .swf Shockwave Flash filetype with the Flash Player in Windows, so if you double click on a .swf file, you'll still get the 'Windows cannot open this file' dialog.

I loaded the .swf file into the stand alone Flash player, and noticed an option under the File Menu - 'Create Projection'. I chose this option, and it seems to convert the .swf file into a standalone Flash executable. So you can just double click the file that it creates, and it opens automatically in Flash player, presumably with no need for you to even have flash installed.

After that I went in the garden for a bit, got bitten by some mosquitoes (seems to be a lot around at the moment), and also took a few photos of a moth and a small caterpillar. Then I copied the pics to my comp and processed them, but for some chees-un, they all came out as .dngs instead of .jpgs. So I deleted all the .dngs, but managed to delete all the raw .cr2 files as well, and didn't realise until after I'd emptied the recycle bin. Doh!

So I started up Handy Recovery to try and recover the files, then after I'd started recovering the recycle bin I remembered that all the RAW files were still on the memory card. So I cancelled the recovery, then copied across the files from the memory card again, and processed them again (but making sure the output was set to JPG instead of DNG).

Food
Breakfast: Lemon marmalade toast sandwich; cup o' tea.
Lunch: Prosciutto cotto ham with sliced cherry plum tomatoes and iceberg lettuce sandwich; a few Aldi/Lidl kettle chips; Slice of cherry and sultana cake; cup o' tea.
Dinner: Chicken pie; green beans; potatoes; gravy. For pudding I had a Strawberry and white chocolate crumble bits or sumat Muller Corner (was very nice). Coffee.
Supper: Dark chocolate digestive; hob-nob; cup o' tea.

No comments: