Page 1 of 1

Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 10:29 am
by schgrypt
Hello everyone,

yesterday I installed Swift Mailer v4b2, today I saw the new version, deleted the old and uploaded the new one instead.

Now when I tried to send the following basic mail:

Code: Select all

$smtp = Swift_SmtpTransport::newInstance('domain.com', 25)
  ->setUsername('info@domain.com')
  ->setPassword('pwd');
 
$mailer = Swift_Mailer::newInstance($smtp);
 
$message = Swift_Message::newInstance('Test');
$message
  ->setTo(array(
    'test@gmail.com' => 'Test Test'
  ))
  ->setFrom(array('test@domain.com' => 'Test Test'))
  ->setBody(
    'Blablabla!',
    'text/html'
  )
  ->addPart('Blablabla!', 'text/plain')
  ;
 
if ($mailer->send($message))
{
  echo "Message sent!";
}
else
{
  echo "Message could not be sent.";
}
instead of sending the message I get the following error:

Code: Select all

Warning: mkdir() [function.mkdir]: SAFE MODE Restriction in effect. The script whose uid is 10570 is not allowed to access /tmp owned by uid 0 in swift-mailer/classes/Swift/KeyCache/DiskKeyCache.php on line 281
 
Fatal error: Uncaught exception 'Swift_IoException' with message 'Failed to create cache directory /tmp/4981d608a8408' in /swift-mailer/classes/Swift/KeyCache/DiskKeyCache.php:283 Stack trace: #0 /swift-mailer/classes/Swift/KeyCache/DiskKeyCache.php(95): Swift_KeyCache_DiskKeyCache->_prepareCache('4981d608a8408') #1 //swift-mailer/classes/Swift/KeyCache/SimpleKeyCacheInputStream.php(73): Swift_KeyCache_DiskKeyCache->setString('4981d608a8408', 'body', 'Message-ID: <12...', 2) #2 swift-mailer/classes/Swift/ByteStream/AbstractFilterableInputStream.php(129): Swift_KeyCache_SimpleKeyCacheInputStream->write('Message-ID: <12...') #3 /swift-mailer/classes/Swift/ByteStream/AbstractFilterableInputS in swift-mailer/classes/Swift/KeyCache/DiskKeyCache.php on line 283
Note: I cut out the domain and other sensitive data.

I installed it on another domain (on the same webspace), there it runs smoothly without any problem, exactly the same test.

So I guess that I mixed up something trying to upgrade, but what exactly where and: how can I fix it?

Thank you in advance for your help :-)
Greetings

//edit: I don't have access to /tmp/ so I can't delete anything probably laying around there

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 11:22 am
by xdecock
You may not have changed lib/preferences.php with a new directory on line 18 or change

Code: Select all

 
if (function_exists('sys_get_temp_dir'))
{
  Swift_Preferences::getInstance()
    -> setTempDir(sys_get_temp_dir())
    -> setCacheType('disk');
}
 
With:

Code: Select all

 
if (function_exists('sys_get_temp_dir') && is_writable(sys_get_temp_dir()))
{
  Swift_Preferences::getInstance()
    -> setTempDir(sys_get_temp_dir())
    -> setCacheType('disk');
}
 
the code change will disable disk cache if temp_dir is not writable

Tell me if it corrects the problems.

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 12:17 pm
by schgrypt
Thank you very much, its working very well now with the "is_writable" check :-)
xdecock wrote:You may not have changed lib/preferences.php with a new directory on line 18
This unfortunately I didn't understand.

Code: Select all

-> setTempDir(sys_get_temp_dir())
Can I change this to whichever dir I want? So f.e.

Code: Select all

-> setTempDir('custom/cachedir')
?

Thank you once again and greetings

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 12:26 pm
by xdecock
you can put another directory, however i recommand using absolute path if possible.

however, just add this at the end of your preference file:

Code: Select all

Swift_Preferences::getInstance()
  -> setTempDir('/absolute_path/to/my/temp/dir/')
  -> setCacheType('disk');
 
and just another trick: add an .htaccess containing

Code: Select all

Deny From All
in your directory if it is below the doc root (reachable from a browser)

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 1:31 pm
by schgrypt
Thank you, htaccess I had already set up :-)

When I change the dir, I get a similar error like before.

I changed it to the following:

Code: Select all

if (function_exists('sys_get_temp_dir'))
{
  Swift_Preferences::getInstance()
    -> setTempDir('/joa/')
    -> setCacheType('disk');
}
 
The directory exists and is writeable, the error is the following:

Code: Select all

Warning: mkdir() [function.mkdir]: Unable to access /joa//4981fd3b65f1b in /swift-mailer/classes/Swift/KeyCache/DiskKeyCache.php on line 281

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 1:36 pm
by xdecock
/joa/ is the path from DOC_ROOT

try

Code: Select all

$_SERVER['DOC_ROOT'].'/joa/'

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 2:24 pm
by schgrypt
Doesn't work unfortunately, I already had the same idea on my own, gives the same error (Warning: mkdir() [function.mkdir]: Unable to access [...] Line 281)

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 2:36 pm
by xdecock
did you tried launching

Code: Select all

mkdir('/joa//4981fd3b65f1b');
(with the right directory path of course)

from a simple script?

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 2:59 pm
by schgrypt
Yes it works. From inside the folder /joa/ itself it works, and from outside it works like this:

Code: Select all

mkdir('joa/4981fd3b65f1b');
mkdir($_SERVER['DOC_ROOT'].'joa/4981fd3b65f1bbbbbbbb');
First I tried it with an additional /, but it doesn't work:

Code: Select all

mkdir('/joa/4981fd3b65f1b');
mkdir($_SERVER['DOC_ROOT'].'/joa/');

Re: Cache Problem after Upgrade b2->b3

Posted: Thu Jan 29, 2009 5:39 pm
by Chris Corbyn
Just to clarify, although editing lib/preferences.php works, the intention is to "override" the default:

Code: Select all

require_once 'lib/swift_required.php';
 
Swift_Preferences::getInstance()->setCacheType('array'); //Or change the temp path
This is a more portable solution when you upgrade Swift Mailer since preferences.php will be overwritten when you update.

However, my assumption that sys_get_temp_dir() would always return a writable directory was flawed so I'll make sure that gets updated in the repository.

Re: Cache Problem after Upgrade b2->b3

Posted: Fri Jan 30, 2009 3:46 am
by schgrypt
Thank you Chris,

using Swift Mailer for the first time I am very happy to learn the best practices.

It works great.

Re: Cache Problem after Upgrade b2->b3

Posted: Fri Jan 30, 2009 11:33 pm
by Chris Corbyn
If you'd like to upgrade to b4, there have been some bug fixes made.

http://swiftmailer.org/betas/Swift-4.0.0-b4.tar.gz

Re: Cache Problem after Upgrade b2->b3

Posted: Sat Jan 31, 2009 1:59 pm
by schgrypt
Nice done, thank you!