Wrapper Operations

With the exception of the url_stat() method, each of the wrapper operations located prior to the const char *label element are used with active stream instances. The purpose of each of these methods are as follows:

stream_opener()

Instantiates a stream instance. This method is called when one of the fopen() userspace functions is called. The php_stream instance returned by this function is the internal representation of a file handle resource such as what is returned by fopen(). All-in-one functions like file(), file_get_contents(), file_put_contents(), readfile(), and too many others to enumerate also use this wrapper ops method when a wrapped resource is requested.

stream_closer()

Called when a stream instance is shutting down. Any resources allocated by stream_opener() should be freed during this phase.

stream_stat()

Analogous to the userspace fstat() function, this method should fill the ssb structurewhich in practice only contains a struct statbuf sb; element.

dir_opener()

Behaves in the same way as stream_opener(), except that it's called in response to the opendir() family of userspace functions. The underlying stream implementation used by the directory streams follows the same basic rules as file streams; however, a directory stream only needs to return struct dirent-sized records containing the filename found in the opened directory.

 

Static Wrapper Operations

The remainder of the wrapper op methods perform atomic operations on URI paths according to the semantics of their protocol wrapper. Only url_stat() and unlink() existed in the PHP 4.3 php_stream_wrapper_ops structure; the remaining methods were defined in PHP 5.0 and should be excluded through appropriate #ifdef blocks.

url_stat()

Used by the stat() family of functions to return file metadata such as access permissions, size, and type; also used to access, modify, and create dates. Although this function appears in the php_stream_wrapper_ops structure all the way back to PHP 4.3 when the streams layer was introduced, it was never executed by the userspace stat() functions until PHP 5.0.

unlink()

Named according to posix filesystem semantics, an unlink() almost always refers to file deletion. If deletion does not make sense for the current wrapper, such as the built-in http:// wrapper, this method should be defined to NULL, allowing the core to issue an appropriate error message.

rename()

When both the $from and $to parameters to the userspace rename() function refer to the same underlying wrapper, PHP will dispatch the rename request to that wrapper's rename method.

mkdir() & rmdir()

These two methods map directly to their userspace counterparts.



The PHP Life Cycle

Variables from the Inside Out

Memory Management

Setting Up a Build Environment

Your First Extension

Returning Values

Accepting Parameters

Working with Arrays and HashTables

The Resource Data Type

PHP4 Objects

PHP5 Objects

Startup, Shutdown, and a Few Points in Between

INI Settings

Accessing Streams

Implementing Streams

Diverting the Stream

Configuration and Linking

Extension Generators

Setting Up a Host Environment

Advanced Embedding

Appendix A. A Zend API Reference

Appendix B. PHPAPI

Appendix C. Extending and Embedding Cookbook

Appendix D. Additional Resources



Extending and Embedding PHP
Extending and Embedding PHP
ISBN: 067232704X
EAN: 2147483647
Year: 2007
Pages: 175
Authors: Sara Golemon

Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net