ZF-10196: Working directory changed in Zend_Mail

Issue Type: Bug Created: 2010-07-21T05:36:37.000+0000 Last Updated: 2012-11-20T21:37:29.000+0000 Status: Open Fix version(s): Reporter: Freek van Rijt (freekazoid) Assignee: None Tags: - Zend_Mail

Related issues: Attachments:


An error in Zend_Mail is causing the working directory to change, this results in a fatal error when trying to include Zend\Mail\Protocol\Exception.php, see the following error:

Warning: require_once(Zend/Mail/Protocol/Exception.php) [function.require-once]: failed to open stream: No such file or directory in D:\www\libraries\Zend\Mail\Protocol\Abstract.php on line 295

Fatal error: require_once() [function.require]: Failed opening required 'Zend/Mail/Protocol/Exception.php' (include_path='../libraries;../application/controllers;../application/models;../application/models/system;../application/forms;../../libraries') in D:\www\libraries\Zend\Mail\Protocol\Abstract.php on line 295

This error has also been reported by other users, see here:… and here:…


Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-21T05:43:53.000+0000

What code do you execute, what is the expected outcome?

Please also attach a stack trace, and please note that it is encouraged to use absolute paths in your include path.

Posted by Freek van Rijt (freekazoid) on 2010-07-21T06:05:23.000+0000

Its happening when simply trying to send a mail. What would be the easiest way for me to get the stack trace for the issue?

Posted by Freek van Rijt (freekazoid) on 2010-07-21T06:59:59.000+0000

Would this be of any help. I ran a backtrace just above the line where the error was triggered:

0 Zend_Mail_Protocol_Abstract->_send(QUIT) called at [D:\www\libraries\Zend\Mail\Protocol\Smtp.php:385]

1 Zend_Mail_Protocol_Smtp->quit() called at [D:\www\libraries\Zend\Mail\Transport\Smtp.php:144]

2 Zend_Mail_Transport_Smtp->__destruct()

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-21T07:58:17.000+0000

Thanks, all that method basically does is call fclose(). Can you please check if this error also happens on linux?

And as mentioned; it is suggested you use absolute paths in your include path rather than relative paths.

Posted by Freek van Rijt (freekazoid) on 2010-07-21T08:14:45.000+0000

Yes, I ran the same script on our test server (which runs linux) and got the same result. It does send the email out though, it looks like where it goes wrong is when it tries to close the connection to the server?

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-21T08:19:07.000+0000

Out of curiosity, why dont you use absolute paths?

Posted by Freek van Rijt (freekazoid) on 2010-07-21T08:26:48.000+0000

We have three seperate environments here - dev: which is basically the local PC, test: which is a closed off test-environment on our server, and production, which is the live environment. Because of this, the path is basically variable, defining it absolute would mean people having to edit it seperately for their own local environment (dev) and also changing it whenever the site goes on test or production environments. We use SVN to exchance it and sync it with our server, so conflicts would be lurking as well. Defining it relative saves all this hassle, and it doesnt matter where on the local filesystem we put the site.

Also it means we dont have to edit the paths for each individual site we produce.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-21T08:26:54.000+0000

I traced down the problem to the php manual:

{quote}Note: Destructors called during the script shutdown have HTTP headers already sent. The working directory in the script shutdown phase can be different with some SAPIs (e.g. Apache).{quote} (

I will have to discuss this but I think it will be closed as wont-fix with the note to simply use absolute paths.

Posted by Dolf Schimmel (Freeaqingme) (freak) on 2010-07-21T08:29:31.000+0000

Frankly, that reason is bogus. You can dynamically determine the absolute path. As is shown in basically any ZF tutorial:

<pre class="highlight">// Define path to application directory
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),

That will dynamically set an absolute include path.

Posted by Freek van Rijt (freekazoid) on 2010-07-21T08:40:31.000+0000

So silly I didn't think of that, changing it to ```` Solved the issue.

Guess the issue is more related to the PHP core rather then Zend itself anyway. Thanks for the help!

Posted by jsnod (afx114) on 2010-09-22T18:41:00.000+0000

I am having a similar issue, with a slight difference: PHP complains about an open_basedir restriction. Here is my error:

<pre class="literal">
Warning:  require_once() [<a href="function.require-once">function.require-once</a>]: open_basedir restriction in effect. File(Zend/Mail/Protocol/Exception.php) is not within the allowed path(s): (/home/username/:/tmp/:/usr/share/pear/:/dev/) in /usr/share/pear/ZendFramework-1.10.8-minimal/library/Zend/Mail/Protocol/Abstract.php on line 295
Fatal error:  Can't load Zend/Mail/Protocol/Exception.php, open_basedir restriction. in /usr/share/pear/ZendFramework-1.10.8-minimal/library/Zend/Mail/Protocol/Abstract.php on line 295

This is odd because my open_basedir value is set to:

<pre class="literal">

My include paths are already absolute, and look like so:

/home/username/library:/home/username/application/models:/home/username/application/models/notifications:/usr/share/pear ````

ZF resides in /usr/share/pear/, so by all indications the file should be able to be found and require'd because it exists in the include_path and my include_path is allowed in open_basedir. If I remove the open_basedir restriction it works as expected, however, I'd rather not do that for security reasons.

Posted by jsnod (afx114) on 2010-09-24T12:40:23.000+0000

After doing additional tests/research, you are right, this is an issue with PHP. The current working directory changes to '/' before object-destructors are called, which is why my open_basedir or throwing an error.

Not sure if this is classified as a "feature" or a "bug" though. :)

Have you found an issue?

See the Overview section for more details.


© 2006-2020 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.