note 63723 deleted from function.stream-context-get-default by bjori
| From: | bjori@php.net | Date: | Wed, 29 Mar 2006 11:24:12 +0000 |
| Subject: | note 63723 deleted from function.stream-context-get-default by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106935@lists.php.net to get a copy of this message | ||
Note Submitter: RQuadling at GMail dot com
----
One way of achieving a system wide default context is to use the php.ini setting auto_prepend_file.
By creating a php script which is placed anywhere in the include_dir paths, you can assign the
default context for all streams.
This is of most use when you are behind a firewall and without the context, stream functions like
fopen('http://www.site.com/page.html')
fail as the proxy server rejects the request.
The auto_prepend_file itself can be anything you like.
The sort of things you can include in it are ...
1 - __autoload()
Control the automatic loading of classes on demand. This helps reduce the amount of loading and
memory usage when a script starts.
2 - Global Uncaught Exception Handling
By placing a set_exception_handler() function in this file you can catch ALL exceptions. A much
nicer way than having the page be just an error.
3 - Global error handling
Pretty much the same as 2 really, but for generic PHP errors. Ideally, these are the things you
should engineer out of the code.
4 - Default Stream Context.
As I mentioned, if you are behind a firewall, then having a default context is EXTREMELY useful.
Thanks to tiago at mdtestudio for alerting me to this function.
The great thing about the auto_prepend_file is that is can be set on a per directory basis. This
means that if you are on a shared host, you can see the auto_prepend_file setting within your
webroot.
There is also auto_append_file which probably has more use for traditional HTML footers. I've
not found a PHP specific reason for this setting. Yet.