WHY? 初次使用新浪SAE的感受[原创]

今天有幸试用了一下新浪的SAE,新浪官方的介绍如下:

Sina App Engine(SAE),是由新浪公司开发和运营的开放云计算平台的核心组成部分。

SAE的目标是实现互联网应用在开发运维上的无缝整合,为App开发者提供稳定、快捷、透明、可控的服务化的平台,并且减少开发者的开发和维护成本。

同时通过对消耗资源的量化,反向作用于开发过程,促进新浪公司互联网应用服务的质量提升。

首先是探针演示:http://asdf.sinaapp.com ,可以看出支持的组件很少

其次从官方给出的文档来看,大概是自定义了一些预定义变量和修改了一些常用函数。

禁用的函数和类如下:

禁用函数

2010年2月1日解禁函数

fprintf,fscanf,ftruncate,fflush,fwrite,fputs,tempnam,file_put_contents,
fputcsv,error_reporting,phpinfo,copy,rename,phpcredits,gzputs,gzwrite,
gzpassthru

2009年10月8日追加禁用函数

gzputs,gzwrite,gzpassthru,openlog,syslog,closelog

最新禁用函数列表

php_logo_guid,php_real_logo_guid,php_egg_logo_guid,zend_logo_guid,
php_sapi_name,php_uname,php_ini_scanned_files,php_ini_loaded_file,readlink,
linkinfo,symlink,link,unlink,exec,system,escapeshellcmd,escapeshellarg,passthru,shell_exec,
proc_open,proc_close,proc_terminate,proc_get_status,proc_nice,getmyuid,getmygid,getmypid,
getmyinode,putenv,getopt,sys_getloadavg,getrusage,get_current_user,set_time_limit,
get_cfg_var,magic_quotes_runtime,set_magic_quotes_runtime,get_magic_quotes_gpc,
get_magic_quotes_runtime,import_request_variables,error_log,error_get_last,debug_zval_dump,
ini_get,ini_get_all,ini_set,ini_alter,ini_restore,get_include_path,set_include_path,
restore_include_path,move_uploaded_file,dl,pclose,popen,rewind,rmdir,umask,fpassthru,
mkdir,stream_select,stream_context_create,stream_context_set_params,stream_context_set_option,
stream_context_get_options,stream_context_get_default,stream_filter_prepend,
stream_filter_append,stream_filter_remove,stream_socket_client,stream_socket_server,
stream_socket_accept,stream_socket_get_name,stream_socket_recvfrom,stream_socket_sendto,
stream_socket_enable_crypto,stream_socket_shutdown,stream_socket_pair,stream_copy_to_stream,
stream_get_contents,stream_set_write_buffer,set_file_buffer,set_socket_blocking,
stream_set_blocking,socket_set_blocking,stream_get_meta_data,stream_get_line,
stream_wrapper_register,stream_register_wrapper,stream_wrapper_unregister,stream_wrapper_restore,
stream_get_wrappers,stream_get_transports,stream_is_local,get_headers,stream_set_timeout,
socket_set_timeout,socket_get_status,mail,apc_add,apc_cache_info,apc_clear_cache,apc_compile_file,
apc_define_constants,apc_delete,apc_fetch,apc_load_constants,apc_sma_info,apc_store,flock,tmpfile

禁用class

XMLWriter,DOMDocument,DOMNotation,DOMXPath,PDOException,PDO,PDOStatement,PDORow,SQLiteDatabase,
SQLiteResult,SQLiteUnbuffered,SQLiteException
可以替代的函数(部分)如下:
file_put_contents用$f = new SaeFetchurl();
$img = $f->fetch('a url of a img');来代替
imagecreatefromgif等一系列图片函数用类似如下的CLASS来代替
  1.  $f new SaeFetchurl();
  2.  $img_data $f->fetch‘http://ss7.sinaimg.cn/bmiddle/488efcbbt7b5c4ae51ca6&690′ );
  3.  $img new SaeImage();
  4.  $img->setData$img_data );
  5.  $img->resize(200)// 等比缩放到200宽
  6.  $img->flipH()// 水平翻转
  7.  $img->flipv()// 垂直翻转
  8.  $new_data $img->exec()// 执行处理并返回处理后的二进制数据
  9.  // 或者可以直接输出
  10.  $img->exec‘jpg’ true )

还有其他的细节就不一一列出。

这样做的好处我自己总结了一下,就是首先通过自建函数库(这种函数都是及其占用资源的)来通过统一的中央引擎来高效处理,并且可以节省服务器开销,提高服务器安全。但是缺点是显而易见的,把所有PHP的原有定义改成新浪的SAE形式的话无疑是一个浩大的工程,而且其必要性也有待于考证。诸如很多占用服务器资源的问题可以通过提高硬件的性能来解决。

还有一点就是说一下这个SAE的BUG或者说是另一种限制吧,以前写PHP脚本的时候我们可以使用<? …?>这种形式,但是在SAE下我们必须使用<?php … ?>这种形式,否则不会认为是PHP文件。

总的来说用两个字来总结新浪的SEA就是折腾,不过这也符合中国人的思维习惯。

Leave a comment

You must be logged in to post a comment.