我正在尝试创建一个运行webpack的简单
PHP脚本.当我在终端中运行它时,它运行正常,但是当我从PHP运行它时,会给我内存错误.这就是我的代码:
PHP:
shell_exec(‘webpack -p –config /home/[username]/config/config.production.js 2>& 1’);
结果如下:
<--- Last few GCs --->
[20920:0x405ede0] 786 ms: Scavenge 40.6 (63.1) -> 31.1 (66.6) MB, 3.4 / 0.0 ms allocation failure
[20920:0x405ede0] 867 ms: Scavenge 45.2 (66.6) -> 35.6 (67.1) MB, 8.5 / 0.0 ms allocation failure
<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: NewSpace::Rebalance Allocation failed - process out of memory
1: node::Abort() [node]
2: 0x8d04bc [node]
3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
5: 0xa7006b [node]
6: v8::internal::MarkCompactCollector::Evacuate() [node]
7: v8::internal::MarkCompactCollector::CollectGarbage() [node]
8: v8::internal::Heap::MarkCompact() [node]
9: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
10: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
11: v8::internal::Factory::NewByteArray(int, v8::internal::PretenureFlag) [node]
12: v8::internal::TranslationBuffer::CreateByteArray(v8::internal::Factory*) [node]
13: v8::internal::compiler::CodeGenerator::PopulateDeoptimizationData(v8::internal::Handle) [node]
14: v8::internal::compiler::CodeGenerator::FinalizeCode() [node]
15: v8::internal::compiler::PipelineImpl::FinalizeCode() [node]
16: v8::internal::compiler::PipelineCompilationJob::FinalizeJobImpl() [node]
17: v8::internal::Compiler::FinalizeCompilationJob(v8::internal::CompilationJob*) [node]
18: v8::internal::OptimizingCompileDispatcher::InstallOptimizedFunctions() [node]
19: v8::internal::StackGuard::HandleInterrupts() [node]
20: v8::internal::Runtime_StackGuard(int, v8::internal::Object**, v8::internal::Isolate*) [node]
21: 0x24ffb0c842fd
free -m给了我这个:
total used free shared buffers cached
Mem: 31956 29146 2810 51 947 24470
-/+ buffers/cache: 3728 28228
Swap: 5999 0 5999
vmstat给了我这个:
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 64 2877076 969764 25058456 0 0 0 10 0 0 0 0 99 0 0
对我来说似乎没有任何明显的记忆问题?
如果我将webpack命令放入npm脚本,并从PHP运行,我会收到此错误:(但是从终端运行npm脚本也很好.)
npm ERR! path /home/[username]
npm ERR! code ENOMEM
npm ERR! errno -12
npm ERR! syscall scandir
npm ERR! ENOMEM: not enough memory, scandir '/home/[username]'
glob error { Error: ENOMEM: not enough memory, scandir '/home/[username]'
errno: -12,
code: 'ENOMEM',
syscall: 'scandir',
path: '/home/[username]' }
我假设这只是由Node抛出的相同错误.当我尝试从PHP运行任何其他NPM命令(如npm列表)时,我也会收到ENOMEM错误,这使我相信它只是一个节点问题而不是其他任何问题.
有谁知道发生了什么或为什么会发生这种情况?
版本:
nvm ls
-> v9.11.1
default -> node (-> v9.11.1)
node -> stable (-> v9.11.1) (default)
stable -> 9.11 (-> v9.11.1) (default)
iojs -> N/A (default)
lts/* -> lts/carbon (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.14.1 (-> N/A)
lts/carbon -> v8.11.1 (-> N/A)
PHP版本:5.5.35
Linux Dist:CentOS版本6.9(最终版)
了shell_exec( ‘ENV’);给我以下内容:
[0] => SERVER_SIGNATURE=
[1] => HTTP_X_HTTPS=1
[2] => SSL_TLS_SNI=www.[mydomain.com]
[3] => UNIQUE_ID=Wt5Y@K33-aQAAGEyFT8AAAAR
[4] => HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
[5] => SERVER_PORT=443
[6] => PHPRC=/home/[username]/public_html
[7] => HTTP_HOST=www.[mydomain.com]
[8] => DOCUMENT_ROOT=/home/[username]/public_html
[9] => SCRIPT_FILENAME=/home/[username]/public_html/template-files/scripts/run-webpack.php
[10] => HTTPS=on
[11] => REQUEST_URI=/template-files/scripts/run-webpack.php
[12] => SCRIPT_NAME=/template-files/scripts/run-webpack.php
[13] => SCRIPT_URI=https://www.[mydomain.com]/template-files/scripts/run-webpack.php
[14] => HTTP_CONNECTION=keep-alive
[15] => REMOTE_PORT=7941
[16] => PATH=/bin:/home/[username]/.nvm/versions/node/v9.11.1/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/home/[username]/perl5/bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/kerberos/bin:/home/[username]/node_modules/.bin:/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/cpanel/composer/bin:/usr/local/bin:/usr/X11R6/bin:/home/[username]/bin
[17] => SCRIPT_URL=/template-files/scripts/run-webpack.php
[18] => CONTEXT_PREFIX=
[19] => PWD=/home/[username]/public_html/template-files/scripts
[20] => SERVER_ADMIN=webmaster@[mydomain.com]
[21] => REQUEST_SCHEME=https
[22] => REDIRECT_STATUS=200
[23] => TZ=America/Los_Angeles
[24] => HTTP_ACCEPT_LANGUAGE=en-US,en;q=0.9
[25] => HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
[26] => REMOTE_ADDR=[myIP]
[27] => SHLVL=1
[28] => SERVER_NAME=www.[mydomain.com]
[29] => SERVER_SOFTWARE=Apache
[30] => QUERY_STRING=
[31] => SERVER_ADDR=[myIP]
[32] => GATEWAY_INTERFACE=CGI/1.1
[33] => HTTP_UPGRADE_INSECURE_REQUESTS=1
[34] => SERVER_PROTOCOL=HTTP/1.1
[35] => HTTP_CACHE_CONTROL=max-age=0
[36] => HTTP_ACCEPT_ENCODING=gzip, deflate, br
[37] => REQUEST_METHOD=GET
[38] => HTTP_COOKIE=_ga=[cookieID…etc]
[39] => CONTEXT_DOCUMENT_ROOT=/home/[username]/public_html
[40] => _=/bin/env
echo shell_exec(‘bash -c“ulimit -a”’);
结果如下:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127717
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 16384
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 400
virtual memory (kbytes, -v) 1048576
file locks (-x) unlimited
如果我能提供有关此问题的更多信息,请与我们联系.谢谢您的帮助!
最佳答案 根据您提供的诊断信息,Web服务器环境正在以内存限制运行(可能通过setrlimit()系统调用).此调用允许进程限制允许它或其子节点分配的内存量.
您需要找到并更改相关设置以提高或禁用内存限制.