include_path assumption elimination

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

include_path assumption elimination

gherson
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
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Ralph Schindler-2
Why don't you simply have ZF in your include_path?  Is there a compelling
reason for it to NOT be in there?

-ralph


On 12/2/08 4:22 PM, "gherson" <[hidden email]> wrote:

>
> 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

--
Ralph Schindler
Software Engineer     | [hidden email]
Zend Framework        | http://framework.zend.com/


Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

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
Ralph Schindler-2 wrote
Why don't you simply have ZF in your include_path?  Is there a compelling
reason for it to NOT be in there?

-ralph
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Ralph Schindler-2
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 :)

On 12/3/08 9:09 AM, "gherson" <[hidden email]> wrote:

>
> 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
>
> Ralph Schindler-2 wrote:
>>
>> 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     | [hidden email]
Zend Framework        | http://framework.zend.com/


Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

weierophinney
Administrator
In reply to this post by gherson
-- gherson <[hidden email]> wrote
(on Wednesday, 03 December 2008, 07:09 AM -0800):
> 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.

> Ralph Schindler-2 wrote:
> > 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       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Matthew Ratzloff
In reply to this post by gherson
> 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

On Wed, Dec 3, 2008 at 7:09 AM, gherson <[hidden email]> wrote:

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

Ralph Schindler-2 wrote:
>
> 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.


Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

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')

best,
George
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

weierophinney
Administrator
-- gherson <[hidden email]> wrote
(on Wednesday, 03 December 2008, 10:48 AM -0800):
> 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       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

SteveWilhelm-2
In reply to this post by Ralph Schindler-2
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.

Ralph Schindler-2 wrote
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 :)

On 12/3/08 9:09 AM, "gherson" <gherson@snet.net> wrote:

>
> 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
>
> Ralph Schindler-2 wrote:
>>
>> 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@zend.com
Zend Framework        | http://framework.zend.com/

Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Tim Nagel
 
 
T

On Thu, Dec 4, 2008 at 18:19, SteveWilhelm <[hidden email]> wrote:

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.


Ralph Schindler-2 wrote:
>
> 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 :)
>
> On 12/3/08 9:09 AM, "gherson" <[hidden email]> wrote:
>
>>
>> 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
>>
>> Ralph Schindler-2 wrote:
>>>
>>> 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     | [hidden email]
> 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.


Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

weierophinney
Administrator
In reply to this post by SteveWilhelm-2
-- SteveWilhelm <[hidden email]> wrote
(on Wednesday, 03 December 2008, 11:19 PM -0800):

>
> 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?

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).


> Ralph Schindler-2 wrote:
> >
> > 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 :)
> >
> > On 12/3/08 9:09 AM, "gherson" <[hidden email]> wrote:
> >
> >>
> >> 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
> >>
> >> Ralph Schindler-2 wrote:
> >>>
> >>> 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     | [hidden email]
> > 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       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

SteveWilhelm-2
thanks for the suggestions.

Matthew Weier O'Phinney-3 wrote
-- SteveWilhelm <steve.wilhelm@gmail.com> wrote
(on Wednesday, 03 December 2008, 11:19 PM -0800):
>
> 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?

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).


> Ralph Schindler-2 wrote:
> >
> > 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 :)
> >
> > On 12/3/08 9:09 AM, "gherson" <gherson@snet.net> wrote:
> >
> >>
> >> 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
> >>
> >> Ralph Schindler-2 wrote:
> >>>
> >>> 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@zend.com
> > 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@zend.com
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Sosy
In reply to this post by weierophinney
Matthew Weier O'Phinney-3 wrote
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?
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

weierophinney
Administrator
-- Sosy <[hidden email]> wrote
(on Thursday, 04 December 2008, 12:47 PM -0800):
> Matthew Weier O'Phinney-3 wrote:
> >
> > 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       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Sosy

Matthew Weier O'Phinney-3 wrote
-- Sosy <sosy@mac.com> wrote
(on Thursday, 04 December 2008, 12:47 PM -0800):
> Matthew Weier O'Phinney-3 wrote:
> >
> > 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>
Great, thanks.
Reply | Threaded
Open this post in threaded view
|

Re: include_path assumption elimination

Matthew Ratzloff
In reply to this post by weierophinney
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

On Thu, Dec 4, 2008 at 7:16 AM, Matthew Weier O'Phinney <[hidden email]> wrote:
-- SteveWilhelm <[hidden email]> wrote
(on Wednesday, 03 December 2008, 11:19 PM -0800):
>
> 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?

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).


> Ralph Schindler-2 wrote:
> >
> > 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 :)
> >
> > On 12/3/08 9:09 AM, "gherson" <[hidden email]> wrote:
> >
> >>
> >> 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
> >>
> >> Ralph Schindler-2 wrote:
> >>>
> >>> 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     | [hidden email]
> > 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       | [hidden email]
Zend Framework           | http://framework.zend.com/