Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Caching swamps server's /tmp folder
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Sun Aug 14, 2011 6:30 am    Post subject: Caching swamps server's /tmp folder Reply with quote

Hello,

I am using Smarty 3.0.8 stable.
I turned on caching for my website, and do not compile pages on every request too (force_compile=false ; compile_check=false and such). Also, $use_sub_dirs=true.

Due to the fact I have many many pages cached, I believe Smarty swamps the /tmp folder for when compiling/caching these pages. It should be odd, since the compiling-folder and caching-folder are not /tmp.

Filling up /tmp folder causes serious damage to my website (and to cpanel, BTW).
Does anyone know how to solve this?
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Sun Aug 14, 2011 9:26 am    Post subject: Re: Caching swamps server's /tmp folder Reply with quote

What are the contents of these files?
Back to top
View user's profile Send private message
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Sun Aug 14, 2011 9:58 am    Post subject: Reply with quote

The script fills up the inode usage quickly. In just a matter of 20 seconds I already have 107 of them and its not deleting any of them.
Back to top
View user's profile Send private message
douglassdavis
Smarty Junkie


Joined: 21 Jan 2008
Posts: 541

PostPosted: Sun Aug 14, 2011 10:08 am    Post subject: Reply with quote

disparate wrote:
The script fills up the inode usage quickly. In just a matter of 20 seconds I already have 107 of them and its not deleting any of them.


I mean, if you open one with a text editor, what's in there?
Back to top
View user's profile Send private message
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Sun Aug 14, 2011 10:54 am    Post subject: Reply with quote

gibberish
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Sun Aug 14, 2011 11:22 am    Post subject: Reply with quote

Maybe you could tell us some file names and some excerpted content?
Smarty should not use /tmp unless you tell it to.

My best guess is they're session files put there by php itself.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Sun Aug 14, 2011 1:56 pm    Post subject: Reply with quote

OK, sorry, the system administrator managed to pull some data (the dot-dot-dot are changes by me for system paths):

Code:


[root@... /tmp]# ls -alh wrtzY2bYt
-rw------- 1 ... ... 25K Aug 13 21:25 wrtzY2bYt

[root@... /tmp]# head -15 wrtzY2bYt
<?php /*%%SmartyHeaderCode:1183516174dce6296804703-76596663%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
'file_dependency' =>
array (
'54215773d8441c8754c098b72380d32c9404c4a3' =>
array (
0 => '/.../public_html/templates/threecolumns/pages/celeb/filmography.tpl',
1 => 1305371071,
2 => 'file',
),
'aeba186be33f71c85f63ac8b878bf906f4ece6c6' =>
array (
0 => '/.../public_html/templates/threecolumns/header.tpl',
1 => 1310203210,
2 => 'file',


Any idea why this kind of files is generated on /tmp or if it is correctly generated - why never deleted by Smarty?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sun Aug 14, 2011 5:15 pm    Post subject: Reply with quote

Smarty first writes compiled and cached template in a tmp file which is then renamed to the final one to avoide race condition.

It looks like your script does not have the right permission to delete files in the tmp folder.
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Sun Aug 14, 2011 10:51 pm    Post subject: Reply with quote

U.Tews wrote:
Smarty first writes compiled and cached template in a tmp file which is then renamed to the final one to avoide race condition.


That may be true, but where does Smarty write to /tmp? Temporary files are written directly to the destination directory, are they not? If Smarty had /tmp hardcoded, it would fail on any windows machine…
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Mon Aug 15, 2011 7:37 am    Post subject: Reply with quote

U.Tews wrote:
It looks like your script does not have the right permission to delete files in the tmp folder.


If the server allows the script to write to a folder, it allows the script to delete, right?
Therefore I don't think it's the case Sad
Any other ideas please please?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Aug 15, 2011 9:51 am    Post subject: Reply with quote

Smarty 3.0.x uses tempnam() to generate a unique filename it can temporary write stuff to. The docs note »If PHP cannot create a file in the specified dir parameter, it falls back on the system default.« Meaning if the temporary file could not be saved to the specified directory (doesn't exist, no permission, …) it will return a filepath you can actually write to - probably relative to /tmp.

Code:
<?php

$path = dirname(__FILE__) . '/not-writable';
$path2 = dirname(__FILE__) . '/writable';
$path3 = dirname(__FILE__) . '/not-existent';
mkdir($path);
chmod($path, 0111);
mkdir($path2);

$tmp = tempnam($path, 'foobar');
$tmp2 = tempnam($path2, 'foobar');
$tmp3 = tempnam($path3, 'foobar');

var_dump($tmp, $tmp2, $tmp3);


only $tmp2 writes to the correct directory, the other 2 go to some weird tmp directory (no, in my case not /tmp).

This suggests you have permission issues, or race conditions where directories are deleted whilst Smarty is trying to write to them.

Smarty 3.1 doesn't use tempnam() anymore.
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Mon Aug 15, 2011 11:02 am    Post subject: Reply with quote

globe wrote:
Smarty 3.0.x uses tempnam() to generate a unique filename it can temporary write stuff to. The docs note »If PHP cannot create a file in the specified dir parameter, it falls back on the system default.« Meaning if the temporary file could not be saved to the specified directory (doesn't exist, no permission, …) it will return a filepath you can actually write to - probably relative to /tmp.

only $tmp2 writes to the correct directory, the other 2 go to some weird tmp directory (no, in my case not /tmp).

This suggests you have permission issues, or race conditions where directories are deleted whilst Smarty is trying to write to them.

Smarty 3.1 doesn't use tempnam() anymore.


If this is the problem I have - it'd actually be very weird, since files are created both on templates-compilation directory and on caching directory. Also, $use_sub_dirs=true seems to do its job since I have many many sub-directories...

Is there any way of effectively debugging this?
Back to top
View user's profile Send private message
rodneyrehm
Administrator


Joined: 30 Mar 2007
Posts: 674
Location: Germany, border to Switzerland

PostPosted: Mon Aug 15, 2011 11:08 am    Post subject: Reply with quote

disparate wrote:
Is there any way of effectively debugging this?


Not that I know of. If my assumptions are right, what you're experiencing are race conditions. Meaning one process determined that the destination directory exists, another process deletes that directory, the first process tries to write to it and fails.

Are you on a high load machine?
_________________
Twitter
Back to top
View user's profile Send private message Visit poster's website
disparate
Smarty Rookie


Joined: 30 Apr 2010
Posts: 8

PostPosted: Mon Aug 15, 2011 11:31 am    Post subject: Reply with quote

globe wrote:

Are you on a high load machine?


Shared hosting Embarassed probably not, then
Back to top
View user's profile Send private message
megawww
Smarty n00b


Joined: 14 Sep 2015
Posts: 1

PostPosted: Mon Sep 14, 2015 9:48 pm    Post subject: Reply with quote

I have same problem. I have even updated to latest Smarty (version 3.1.27) and no fix for this. Also, I am using a dedicated server.

Everything was fine till one month ago, since I have changed the dedicated server (another server, another OS - currently Ubuntu). Otherwise, no change on the website.

So definitely there is some kind of permission issue or misconfiguration.

The folder where templates cache are stored is CHMOD'ed 777 and the files are succesfully generated there. But, the /tmp is filled instantly with temp generated template files - so like thousands of files.

As a result of /tmp filling up, every few days, the server is hanging, MySQL no longer accept connections, no other files can be created etc.

For now, I have setup a crontab to delete files once per day (older than 1 day) from /tmp folder, but this is not meant to be a permanent solution:

Code:
0 5 * * * /usr/bin/find /tmp/* -type f -atime +1 -exec rm -f {} \;


What could be the issue? Do you have any ideas with this issue?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP