Discussion:
include_path assumption elimination
gherson
2008-12-02 22:22:20 UTC
Permalink
Solution share:

Ran into a problem today with the Zend/Search/Lucene.php's includes of type
require_once 'Zend/Search/Lucene/Exception.php';

These assume that the originally browsed PHP script is in every case exactly
3 folders up from Exception.php. That wasn't the case for me, so in the
script that includes Lucene.php, I wrapped that include in two lines:
ini_set('include_path', '.;' . dirname(__FILE__)); // (Use : instead of
; on Unix.)
require_once 'Zend/Search/Lucene.php';
ini_restore('include_path');

That didn't come to me in an eye blink, though, so maybe a similar ini_set()
and ini_restore() line can be put atop and bottom, respectively, of
Lucene.php?

Similarly, if not as easily, maybe PHP's require('path/to/file') and
include('path/to/file') functions can be given an option to use the
immediate includer's directory as the starting point to 'path/to/file'?
That'd allow me to avoid long-winded
require_once dirname(__FILE__) .
"/path/from/current/file/to/anotherinclude.inc";
statements.

thanks,
George
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20802356.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Ralph Schindler
2008-12-03 14:59:38 UTC
Permalink
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?

-ralph
Post by gherson
Ran into a problem today with the Zend/Search/Lucene.php's includes of type
require_once 'Zend/Search/Lucene/Exception.php';
These assume that the originally browsed PHP script is in every case exactly
3 folders up from Exception.php. That wasn't the case for me, so in the
ini_set('include_path', '.;' . dirname(__FILE__)); // (Use : instead of
; on Unix.)
require_once 'Zend/Search/Lucene.php';
ini_restore('include_path');
That didn't come to me in an eye blink, though, so maybe a similar ini_set()
and ini_restore() line can be put atop and bottom, respectively, of
Lucene.php?
Similarly, if not as easily, maybe PHP's require('path/to/file') and
include('path/to/file') functions can be given an option to use the
immediate includer's directory as the starting point to 'path/to/file'?
That'd allow me to avoid long-winded
require_once dirname(__FILE__) .
"/path/from/current/file/to/anotherinclude.inc";
statements.
thanks,
George
--
Ralph Schindler
Software Engineer | ralph.schindler-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
gherson
2008-12-03 15:09:57 UTC
Permalink
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.

best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20814738.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Ralph Schindler
2008-12-03 15:14:53 UTC
Permalink
Actually, if its not in your systems include_path (as opposed to the set for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.

Have a look at this page of the quickstart:

http://framework.zend.com/docs/quickstart/create-a-bootstrap-file

That should explain a few things.. Take notice to the set_include_path
call.

-ralph

PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes :)
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Software Engineer | ralph.schindler-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
SteveWilhelm
2008-12-04 07:19:18 UTC
Permalink
Why does Cal Evans on page thirteen of his book, Guide to Programming with
Zend Framework, state:

"Heck, it [using set_include_path()] works okay in production if you don't
have more than 5 people at a time hitting your site."

Is there some kind of performance scaling problem with the method you are
suggesting? If so, what is the recommended method for setting a path in a
scalable production environment?

- Steve W.
Post by Ralph Schindler
Actually, if its not in your systems include_path (as opposed to the set for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
That should explain a few things.. Take notice to the set_include_path
call.
-ralph
PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes :)
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Zend Framework | http://framework.zend.com/
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20828491.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Tim Nagel
2008-12-04 10:12:16 UTC
Permalink
Check out http://framework.zend.com/manual/en/performance.html


T
Post by SteveWilhelm
Why does Cal Evans on page thirteen of his book, Guide to Programming with
"Heck, it [using set_include_path()] works okay in production if you don't
have more than 5 people at a time hitting your site."
Is there some kind of performance scaling problem with the method you are
suggesting? If so, what is the recommended method for setting a path in a
scalable production environment?
- Steve W.
Post by Ralph Schindler
Actually, if its not in your systems include_path (as opposed to the set for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
That should explain a few things.. Take notice to the set_include_path
call.
-ralph
PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes :)
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though,
such
Post by Ralph Schindler
Post by gherson
as
per my ini_set('include_path',...) suggestion? It appears there's a
base
Post by Ralph Schindler
Post by gherson
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Zend Framework | http://framework.zend.com/
--
http://www.nabble.com/include_path-assumption-elimination-tp20802356p20828491.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Matthew Weier O'Phinney
2008-12-04 15:16:04 UTC
Permalink
Post by SteveWilhelm
Why does Cal Evans on page thirteen of his book, Guide to Programming with
"Heck, it [using set_include_path()] works okay in production if you don't
have more than 5 people at a time hitting your site."
Is there some kind of performance scaling problem with the method you are
suggesting? If so, what is the recommended method for setting a path in a
scalable production environment?
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
Post by SteveWilhelm
Post by Ralph Schindler
Actually, if its not in your systems include_path (as opposed to the set for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
That should explain a few things.. Take notice to the set_include_path
call.
-ralph
PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes :)
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Zend Framework | http://framework.zend.com/
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20828491.html
Sent from the Zend MFS mailing list archive at Nabble.com.
--
Matthew Weier O'Phinney
Software Architect | matthew-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
SteveWilhelm
2008-12-04 18:18:13 UTC
Permalink
thanks for the suggestions.
Post by Matthew Weier O'Phinney
Post by SteveWilhelm
Why does Cal Evans on page thirteen of his book, Guide to Programming with
"Heck, it [using set_include_path()] works okay in production if you don't
have more than 5 people at a time hitting your site."
Is there some kind of performance scaling problem with the method you are
suggesting? If so, what is the recommended method for setting a path in a
scalable production environment?
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
Post by SteveWilhelm
Post by Ralph Schindler
Actually, if its not in your systems include_path (as opposed to the
set
Post by Ralph Schindler
for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
That should explain a few things.. Take notice to the set_include_path
call.
-ralph
PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes
:)
Post by Ralph Schindler
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though,
such
Post by Ralph Schindler
Post by gherson
as
per my ini_set('include_path',...) suggestion? It appears there's a
base
Post by Ralph Schindler
Post by gherson
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Zend Framework | http://framework.zend.com/
--
http://www.nabble.com/include_path-assumption-elimination-tp20802356p20828491.html
Sent from the Zend MFS mailing list archive at Nabble.com.
--
Matthew Weier O'Phinney
Zend Framework | http://framework.zend.com/
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20839075.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Sosy
2008-12-04 20:47:13 UTC
Permalink
Post by Matthew Weier O'Phinney
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
How do I use rewrite without the .htaccess?
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20842127.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Matthew Weier O'Phinney
2008-12-04 21:07:11 UTC
Permalink
Post by Sosy
Post by Matthew Weier O'Phinney
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
How do I use rewrite without the .htaccess?
You put it in your vhost definition:

<VirtualHost *:80>
...

RewriteEngine On
...
</VirtualHost>
--
Matthew Weier O'Phinney
Software Architect | matthew-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
Sosy
2008-12-04 21:18:17 UTC
Permalink
Post by Matthew Weier O'Phinney
Post by Sosy
Post by Matthew Weier O'Phinney
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
How do I use rewrite without the .htaccess?
<VirtualHost *:80>
...
RewriteEngine On
...
</VirtualHost>
Great, thanks.
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20842667.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Matthew Ratzloff
2008-12-05 00:23:57 UTC
Permalink
I think set_include_path() is fine, but caching it in your virtual host
definition is best. As Matthew indicated, if you're worried about
performance the last thing you should be using is .htaccess.
-Matt
Post by Matthew Weier O'Phinney
Post by SteveWilhelm
Why does Cal Evans on page thirteen of his book, Guide to Programming
with
Post by SteveWilhelm
"Heck, it [using set_include_path()] works okay in production if you
don't
Post by SteveWilhelm
have more than 5 people at a time hitting your site."
Is there some kind of performance scaling problem with the method you are
suggesting? If so, what is the recommended method for setting a path in a
scalable production environment?
Put it in the vhost definition, or your .htaccess (it's best to have
.htaccess use disabled in production, however, as it's a performance
hit).
Post by SteveWilhelm
Post by Ralph Schindler
Actually, if its not in your systems include_path (as opposed to the
set
Post by SteveWilhelm
Post by Ralph Schindler
for
the project in say the .htaccess or vhost), the typical place users are
expected to set this value is in the bootstrap or index file.
http://framework.zend.com/docs/quickstart/create-a-bootstrap-file
That should explain a few things.. Take notice to the set_include_path
call.
-ralph
PS. Notice the PATH_SEPARATOR const. It will save you many keystrokes
:)
Post by SteveWilhelm
Post by Ralph Schindler
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though,
such
Post by SteveWilhelm
Post by Ralph Schindler
Post by gherson
as
per my ini_set('include_path',...) suggestion? It appears there's a
base
Post by SteveWilhelm
Post by Ralph Schindler
Post by gherson
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
Ralph Schindler
Zend Framework | http://framework.zend.com/
--
http://www.nabble.com/include_path-assumption-elimination-tp20802356p20828491.html
Post by SteveWilhelm
Sent from the Zend MFS mailing list archive at Nabble.com.
--
Matthew Weier O'Phinney
Zend Framework | http://framework.zend.com/
Matthew Weier O'Phinney
2008-12-03 15:20:56 UTC
Permalink
Post by gherson
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.
It makes zero sense to do that in ZF, as it would need to be done in
each and every class file, adding overhead and creating a maintenance
nightmare. Additionally, when using symlinks, this gets problematic.
It's much, much better to set the include_path in the code consuming the
library.
Post by gherson
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a
compelling reason for it to NOT be in there?
--
Matthew Weier O'Phinney
Software Architect | matthew-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
Matthew Ratzloff
2008-12-03 17:27:02 UTC
Permalink
Post by Ralph Schindler
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
That's another solution, thanks.


Well, that's not another solution, that's the solution. It's at the very
beginning of every quick start, tutorial, and book about Zend Framework.
That's also how PEAR and many other PHP frameworks work.

fw-formats?

-Matt
Post by Ralph Schindler
That's another solution, thanks. Why not remove the hurdle, though, such as
per my ini_set('include_path',...) suggestion? It appears there's a base
script per ZF library in which that can be cleanly done.
best,
George
Post by Ralph Schindler
Why don't you simply have ZF in your include_path? Is there a compelling
reason for it to NOT be in there?
-ralph
--
http://www.nabble.com/include_path-assumption-elimination-tp20802356p20814738.html
Sent from the Zend MFS mailing list archive at Nabble.com.
gherson
2008-12-03 18:48:09 UTC
Permalink
The create-a-bootstrap-file page wasn't there when I started use of ZF. Why
make unnecessary assumptions about the user keeping up with your best
practices in any case? If 2 lines to make this setup item go away is too
much, add 1 assertion to save him time on the fix. E.g.,
assert('strstr(get_ini("include_path"),"Zend")!==false')

best,
George
--
View this message in context: http://www.nabble.com/include_path-assumption-elimination-tp20802356p20819133.html
Sent from the Zend MFS mailing list archive at Nabble.com.
Matthew Weier O'Phinney
2008-12-03 19:11:27 UTC
Permalink
Post by gherson
The create-a-bootstrap-file page wasn't there when I started use of ZF. Why
make unnecessary assumptions about the user keeping up with your best
practices in any case? If 2 lines to make this setup item go away is too
much, add 1 assertion to save him time on the fix. E.g.,
assert('strstr(get_ini("include_path"),"Zend")!==false')
The issue is that we'd need to do that for *each and every class file*.
This would be a ridiculous requirement that would also generate a ton of
performance overhead. Don't believe me? head over to the pear-dev
mailing list archives and look at the debates about include_path usage
surrounding PEAR2 coding standards.

While the "create-a-bootstrap-file" page may not have been there when
you started using ZF (it's been present for around 3 months, btw),
*every* intro tutorial to ZF I've ever read or written shows setting up
the include_path to point to the ZF installation. This is often a
one-liner for your ZF-consuming applications:

set_include_path('path/to/framework/library' . PATH_SEPARATOR . get_include_path());

Alternately, set it explicitly in your .htaccess or vhost.

This requirement is *not* going away anytime soon.
--
Matthew Weier O'Phinney
Software Architect | matthew-C1q0ot2/***@public.gmane.org
Zend Framework | http://framework.zend.com/
Loading...