小编bui*_*ure的帖子

php7 oauth非法内存分配

介绍

在复杂的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);
Run Code Online (Sandbox Code Playgroud)

错误信息

*20 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 18446744069414584466 bytes)
Run Code Online (Sandbox Code Playgroud)

描述

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

$oauthClient->fetch($callUrl, $strPostData, $method, $headers);
Run Code Online (Sandbox Code Playgroud)

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

独立

<?php

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

$headers = array('accept' => 'application/json');
$callUrl …
Run Code Online (Sandbox Code Playgroud)

oauth-2.0 php-7

10
推荐指数
1
解决办法
646
查看次数

标签 统计

oauth-2.0 ×1

php-7 ×1