tags:

views:

62

answers:

1

Hello,

We're running rather big website (~400K page views daily) and using Smarty as templates engine. HTML coder changes templates every day and every template change (almost every) causes website crash because of PHP Fatal error: Call to undefined function _smarty_tplfunc_f0cb5c08ca1726d224308f2f6bd56b4f_0() in ... PS: Yes, we're using $smarty->compile_check to see template changes immediately.

To fix this error, we're cleaning all website cache. I don't feel comfortable with it!

Who know, how can I fix it? And why this error occures every time (almost every time) when template is changed.

Thank you.

A: 

The best way to avoid this kind of issue is to upload to a temporary file, then rename it. That way there's no chance for a partial file appearing.

As for why it happens every time, think about it. 400k page views per day == 4.6 requests per second average. Considering most sites I've ever seen have far more traffic over specific hours (during the day), I'd suspect that you're seeing upwards of 10 to 20 requests per second. at that rate, if the file write (because of the upload) takes longer than 0.05 seconds, the chance of a read while it's being written to rises sharply.

So your choices (In order of most robust to least. You can always do multiple):

  1. Do the uploads after hours when traffic is (hopefully) lower...
  2. Use a FTP server that does the renaming bit for you.
  3. Manually rename the file when you upload the new one. (Important; Rename to overwrite the original. don't delete or move the original first)...
  4. Hack Smarty to ignore the new files with a timestamp less than about 10 to 30 seconds old (Simply call filemtime() to determine when it was last modified. Be sure to call clearstatcache() first so you don't get an old time)...
ircmaxell
Hello, thank for your advices. I will try them tomorrow. Especially I like idea with modifying Smarty code a little.
Kirzilla
I've just tried use `touch template.tpl` instead of cleaning cache - it works great, so I think renaming will help (will check a little later)
Kirzilla