oauth-2.0 – php7 oauth非法内存分配

前端之家收集整理的这篇文章主要介绍了oauth-2.0 – php7 oauth非法内存分配前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
介绍 @H_502_1@在复杂的Web应用程序中运行时,生成PHP7进程尝试在使用oauth模块时分配非法内存量(18446744069414584466字节). fpm管理器重新启动后,在触发此代码2-5次后出现错误

$oauthClient = new \OAuth($consumerKey,$consumerSecret,OAUTH_SIG_METHOD_HMACSHA1,OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauthClient->disableSSLChecks();
$oauthClient->setToken($token,$tokenSecret);
$oauthClient->fetch($callUrl,$strPostData,$method,$headers);
@H_502_1@错误信息

*20 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 18446744069414584466 bytes)
@H_502_1@描述

@H_502_1@错误消息中提到的受影响的行是oauth客户端的fetch方法

$oauthClient->fetch($callUrl,$headers);
@H_502_1@我试图通过在循环中执行它并随着时间观察内存使用情况来隔离相关代码.使用和分配的内存量似乎随着时间的推移而稳定增长,但没有预期的那么快(可能只是oauthClient缓存响应)

@H_502_1@独立

@H_502_1@码

<?PHP

$strPostData = '';
$method = 'GET';
$consumerKey = '<consumerKey>';
$consumerSecret = '<consumerSecret>';
$token = '<token>';
$tokenSecret = '<tokenSecret>';
$url = '<url>';

$headers = array('accept' => 'application/json');
$callUrl = $url;

if ($method === 'POST' || $method === 'PUT') {
    $headers['Content-Type'] = 'application/json';
}

$oauthClient = new \OAuth($consumerKey,$tokenSecret);

do {
        $oauthClient->fetch($callUrl,$headers);
        $response = $oauthClient->getLastResponse();
        fwrite(STDOUT,'Allocated Memory: '. memory_get_usage(false) . PHP_EOL);
        fwrite(STDOUT,'Used Memory: '. memory_get_usage(true) . PHP_EOL);
} while (true);
?>
@H_502_1@产量

Allocated Memory: 236920
Used Memory: 262144
...
Allocated Memory: 263168
Used Memory: 524288
...
Allocated Memory: 289504
Used Memory: 524288
...
Used Memory: 524288
Allocated Memory: 331888
...
Allocated Memory: 395976
Used Memory: 524288
...
Allocated Memory: 428600
Used Memory: 524288
...
@H_502_1@核心&模块版本

Core: 7.0.8-3+deb.sury.org~trusty+1
date: 7.0.8-3+deb.sury.org~trusty+1
libxml: 7.0.8-3+deb.sury.org~trusty+1
openssl: 7.0.8-3+deb.sury.org~trusty+1
pcre: 7.0.8-3+deb.sury.org~trusty+1
zlib: 7.0.8-3+deb.sury.org~trusty+1
filter: 7.0.8-3+deb.sury.org~trusty+1
hash: 1.0
pcntl: 7.0.8-3+deb.sury.org~trusty+1
Reflection: 7.0.8-3+deb.sury.org~trusty+1
SPL: 7.0.8-3+deb.sury.org~trusty+1
session: 7.0.8-3+deb.sury.org~trusty+1
standard: 7.0.8-3+deb.sury.org~trusty+1
MysqLnd: MysqLnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $
PDO: 7.0.8-3+deb.sury.org~trusty+1
xml: 7.0.8-3+deb.sury.org~trusty+1
bcmath: 7.0.8-3+deb.sury.org~trusty+1
calendar: 7.0.8-3+deb.sury.org~trusty+1
ctype: 7.0.8-3+deb.sury.org~trusty+1
curl: 7.0.8-3+deb.sury.org~trusty+1
dom: 20031129
mbstring: 7.0.8-3+deb.sury.org~trusty+1
fileinfo: 1.0.5
ftp: 7.0.8-3+deb.sury.org~trusty+1
gd: 7.0.8-3+deb.sury.org~trusty+1
gettext: 7.0.8-3+deb.sury.org~trusty+1
iconv: 7.0.8-3+deb.sury.org~trusty+1
json: 1.4.0
exif: 1.4 $Id: 8bdc0c8f27c2c9dd1f7551f1f9fe3ab57a06a4b1 $
MysqLi: 7.0.8-3+deb.sury.org~trusty+1
OAuth: 2.0.2
pdo_MysqL: 7.0.8-3+deb.sury.org~trusty+1
pdo_sqlite: 7.0.8-3+deb.sury.org~trusty+1
Phar: 2.0.2
posix: 7.0.8-3+deb.sury.org~trusty+1
readline: 7.0.8-3+deb.sury.org~trusty+1
shmop: 7.0.8-3+deb.sury.org~trusty+1
SimpleXML: 7.0.8-3+deb.sury.org~trusty+1
soap: 7.0.8-3+deb.sury.org~trusty+1
sockets: 7.0.8-3+deb.sury.org~trusty+1
sqlite3: 0.7-dev
ssh2: 0.13-dev
sysvmsg: 7.0.8-3+deb.sury.org~trusty+1
sysvsem: 7.0.8-3+deb.sury.org~trusty+1
sysvshm: 7.0.8-3+deb.sury.org~trusty+1
tokenizer: 7.0.8-3+deb.sury.org~trusty+1
wddx: 7.0.8-3+deb.sury.org~trusty+1
xmlreader: 7.0.8-3+deb.sury.org~trusty+1
xmlwriter: 7.0.8-3+deb.sury.org~trusty+1
xsl: 7.0.8-3+deb.sury.org~trusty+1
zip: 1.13.3
Zend OPcache: 7.0.8-3+deb.sury.org~trusty+1
我遇到了类似的问题,并将其跟踪到使用启用了opcache的oauth扩展的问题.对于我遇到的确切情况,实际上有一个bug是开放的错误https://bugs.php.net/bug.php?id=73310.我们找到了这个问题的潜在解决方法,直到它完全解决,将利用ocuth扩展的文件列入黑名单以清除异常. @H_502_1@您可以使用opcache.blacklist-filename选项-http://php.net/manual/en/opcache.configuration.php#ini.opcache.blacklist-filename将opcache的文件列入黑名单.

@H_502_1@>在服务器上添加一个txt文件,其中包含您希望在其自己的行中列入黑名单的每个文件的完整路径>在编辑模式下打开opcache.ini(例如sudo vi /etc/PHP/7.0/mods-available/opcache.ini)>编辑opcache.blacklist-filename选项以指向使用列入黑名单的文件创建的txt文件>如果您使用的是fpm,请重新启动它

猜你在找的PHP相关文章