簡體   English   中英

如果使用PHP運行編譯,則無法分配內存

[英]Cannot allocate memory if running the compilation with PHP

我目前正在使用一個運行以下命令來運行Passenger編譯的PHP腳本:

passenger-install-apache2-module --auto

如果我在SSH中運行該命令,則可以正常運行,但是當我從PHP使用exec()啟動該命令時,就會收到“虛擬內存耗盡:無法分配內存”。

c++ -o buildout/support-binaries/CoreMain.o  -Isrc/agent -Isrc/cxx_supportlib -Isrc/cxx_supportlib/vendor-copy -Isrc/cxx_supportlib/vendor-modified -Isrc/cxx_supportlib/vendor-modified/libev -Isrc/cxx_supportlib/vendor-copy/libuv/include -D_REENTRANT -I/usr/local/include -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-missing-field-initializers -feliminate-unused-debug-symbols -feliminate-unused-debug-types -fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED -Wno-attributes -ggdb -DHAS_ALLOCA_H -DHAVE_ACCEPT4 -DHAS_SFENCE -DHAS_LFENCE -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -std=gnu++11 -Wno-unused-local-typedefs -DHASH_NAMESPACE="__gnu_cxx" -DHASH_MAP_HEADER="<hash_map>" -DHASH_MAP_CLASS="hash_map" -DHASH_FUN_H="<hash_fun.h>" -c src/agent/Core/CoreMain.cpp
virtual memory exhausted: Cannot allocate memory
rake aborted!
Command failed with status (1): [c++ -o buildout/support-binaries/CoreMain.o  -Isrc/agent -Isrc/cxx_supportlib -Isrc/cxx_supportlib/vendor-copy -Isrc/cxx_supportlib/vendor-modified -Isrc/cxx_supportlib/vendor-modified/libev -Isrc/cxx_supportlib/vendor-copy/libuv/include -D_REENTRANT -I/usr/local/include -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-missing-field-initializers -feliminate-unused-debug-symbols -feliminate-unused-debug-types -fvisibility=hidden -DVISIBILITY_ATTRIBUTE_SUPPORTED -Wno-attributes -ggdb -DHAS_ALLOCA_H -DHAVE_ACCEPT4 -DHAS_SFENCE -DHAS_LFENCE -DPASSENGER_DEBUG -DBOOST_DISABLE_ASSERTS -std=gnu++11 -Wno-unused-local-typedefs -DHASH_NAMESPACE="__gnu_cxx" -DHASH_MAP_HEADER="<hash_map>" -DHASH_MAP_CLASS="hash_map" -DHASH_FUN_H="<hash_fun.h>" -c src/agent/Core/CoreMain.cpp]
/usr/local/rvm/gems/ruby-2.3.3/gems/passenger-5.1.2/build/support/cplusplus.rb:52:in `run_compiler'
/usr/local/rvm/gems/ruby-2.3.3/gems/passenger-5.1.2/build/support/cplusplus.rb:102:in `compile_cxx'
/usr/local/rvm/gems/ruby-2.3.3/gems/passenger-5.1.2/build/support/cplusplus.rb:160:in `block in define_cxx_object_compilation_task'
Tasks: TOP => apache2 => buildout/support-binaries/PassengerAgent => buildout/support-binaries/CoreMain.o
(See full trace by running task with --trace)

我已經嘗試了具有8GB RAM的服務器。 我在/ var / log / messages中沒有收到任何OOM,所以我認為內存不是問題。

知道為什么僅從exec()運行時會出現此錯誤嗎?

我終於找到了問題。 我的PHP腳本作為WHM(cPanel)插件運行,似乎WHM在運行腳本之前設置了ulimit。 由於腳本是以root身份運行的,因此我只需要在運行bash之前修改ulimit。

exec("ulimit -m unlimited -v unlimited; bash myscript.sh");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM