PHP Wrapper在SAE上的应用方法

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP Wrapper在SAE上的应用方法脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文讲述了PHP WrapPEr在SAE上的应用方法分享给大家供大家参考,具体如下:

一、PHP Wrapper是什么

PHP 4.3开始PHP开始允许用户通过stream_wrapper_register()自定义URL风格的协议。用户使用fopen(),copy()文件系统函数对封装协议进行操作时,PHP调用注册协议时所提供的类中相应的函数PHP手册中给了一个例子,它将VARiableStream类注册为var://协议,通过这个协议,用户可以使用文件系统函数直接读写全局变量。例如,用户可以通过 “var://foo” 读写 $GLOBALS['foo'] 。

二、SAE为什么需要PHP Wrapper

出于性能和安全方面的考虑,SAE平台上禁用了本地文件读写和对外的数据抓取。相应的,我们提供了对应的服务来做同样的事情。

由于新服务的接口和PHP本身的接口不太一样,专门为我们平台开发的程序当然不会存在问题,但是大量已有的程序和开项目,就面临着繁杂的迁移工作。而使用PHP Wrapper对我们的服务的接口进行封装之后,用户就可以更方便地将程序迁移到SAE平台。

三、如何写PHP Wrapper

要通过PHP Wrapper封装一个协议,首先,我们需要写一个 streamWrapper 类,类名可自定义,类的格式为:

<PRe class="brush:PHp;"> streamWrapper { public resource $context ; __construct ( void ) public bool dir_closedir ( void ) public bool dir_opendir ( string $path,int $options ) public string dir_readdir ( void ) public bool dir_rewinddir ( void ) public bool mkdir ( string $path,int $mode,int $options ) public bool rename ( string $path_From,string $path_to ) public bool rmdir ( string $path,int $options ) public resource stream_cast ( int $cast_as ) public void stream_close ( void ) public bool stream_eof ( void ) public bool stream_flush ( void ) public bool stream_lock ( mode $operation ) public bool stream_open ( string $path,string $mode,int $options,string &$opened_path ) public string stream_read ( int $count ) public bool stream_seek ( int $offset,int $whence = SEEK_SET ) public bool stream_set_option ( int $option,int $arg1,int $arg2 ) public array stream_stat ( void ) public int stream_tell ( void ) public int stream_wrITe ( string $data ) public bool unlink ( string $path ) public array url_stat ( string $path,int $flags ) }

脚本宝典总结

以上是脚本宝典为你收集整理的PHP Wrapper在SAE上的应用方法全部内容,希望文章能够帮你解决PHP Wrapper在SAE上的应用方法所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:SAESAEWrapper