Saturday, December 8, 2007

Peculiar Workarounds

I just wanted to capture some miscellaneous workarounds that I've had to use while creating a site in PHP on a shared host.

For now, I've just been using a shared Linux hosting plan. (BTW, don't ever use 1&1! Besides being terribly slow and going down randomly for hours in the middle of the day, their support is just atrocious. I once had a problem scheduling cron jobs, so I decided to email them for help. Their reply was of no use. I ended up figuring it out on my own though, so I sent another email to them to tell them how I solved the problem — the crontab file needed a newline at the end. They completely didn't get what I was saying and acted as if I was still having a problem.)

And on this shared host, PHP5 is run as a cgi. Running phpinfo(), I found that in order to modify the php.ini settings, you had to include the php.ini file in every directory. (Be careful. A php.ini file overrides all settings, and defaults are used for unspecified settings. It doesn't extend the current settings.) So I made a script that copies the php.ini file I made into every subdirectory.

An alternative if you're using a bootstrap file, is to set the ini settings programmatically in the bootstrap using ini-set.

Another peculiar problem I found on this shared host using the Zend Framework had something to do with the rewriting of URLs. When I had a controller named Posts and tried to go to a URL like /posts/view, it would work perfectly on my server but would give a 404 on the shared host. I actually already mentioned this at the end of another post, but I thought it should be pointed out because I just know this is the kind of thing I will forget about and spend hours trying to fix again.

The workaround I found was to create a dummy directory called posts (or whatever your controller is named) and duplicate the RewriteRules in a .htaccess file in that directory. In other words, something like this:
RewriteEngine on
RewriteBase /

RewriteRule !\.(js|ico|gif|jpg|png|css|flv|swf)$ index.php

I think it had something to do with the fact that I was using Apache 2.0 while the shared host was using 1.x. On the shared host, it was looking for a directory called posts instead of using the RewriteRules in the .htaccess file in the web root directory.

No comments: