note 63723 added to function.stream-context-get-default
| From: | RQuadling at GMail dot com | Date: | Wed, 29 Mar 2006 09:43:54 +0000 |
| Subject: | note 63723 added to function.stream-context-get-default | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-106930@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 66.163.161.117
Probable Submitter: 83.104.121.66 (proxied: 1.1 BANDEXCH)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.stream-context-get-default.php
Edit -- http://master.php.net/note/edit/63723
Del: integrated -- http://master.php.net/note/delete/63723/integrated
Del: useless -- http://master.php.net/note/delete/63723/useless
Del: bad code -- http://master.php.net/note/delete/63723/bad+code
Del: spam -- http://master.php.net/note/delete/63723/spam
Del: non-english -- http://master.php.net/note/delete/63723/non-english
Del: in docs -- http://master.php.net/note/delete/63723/in+docs
Del: other reasons-- http://master.php.net/note/delete/63723
Reject -- http://master.php.net/note/reject/63723
Search -- http://master.php.net/manage/user-notes.php