命令行上的PHP显示“Out of Memory”,没有文件名,行号或内存值

前端之家收集整理的这篇文章主要介绍了命令行上的PHP显示“Out of Memory”,没有文件名,行号或内存值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我最初发布于 https://stackoverflow.com/questions/9665189/php-on-command-line-displays-out-of-memory,但建议在此发布.

当脚本中的内存不足时,这不是正常的致命错误,因为它没有提供文件名,行号或使用的内存量.每当我尝试在命令行上运行PHP时,它只是说“内存不足”,或者当你传递一个脚本或者只是自己运行PHP时.即使尝试运行不存在的脚本也会产生相同的消息.

换句话说,我明白了:

  1. dan@server [~]# PHP
  2. Out of memory
  3. dan@server [~]# PHP test.PHP
  4. Out of memory
  5. dan@server [~]# PHP doesntexist.PHP
  6. Out of memory
  7. dan@server [~]# PHP -v
  8. Out of memory

但是通过Apache的PHP工作非常好.我只是在CLI上得到了这个错误.

有问题的机器运行的是CentOS版本5.7(最终版),它是64位和PHP 5.3.10.它是一个专用的服务器.

我尝试过运行ulimit -a,如同建议的那样,这是输出

  1. core file size (blocks,-c) 200000
  2. data seg size (kbytes,-d) 200000
  3. scheduling priority (-e) 0
  4. file size (blocks,-f) unlimited
  5. pending signals (-i) 37888
  6. max locked memory (kbytes,-l) 32
  7. max memory size (kbytes,-m) 200000
  8. open files (-n) 100
  9. pipe size (512 bytes,-p) 8
  10. POSIX message queues (bytes,-q) 819200
  11. real-time priority (-r) 0
  12. stack size (kbytes,-s) 8192
  13. cpu time (seconds,-t) unlimited
  14. max user processes (-u) 35
  15. virtual memory (kbytes,-v) 200000
  16. file locks (-x) unlimited

root上的free -m给出了:

  1. total used free shared buffers cached
  2. Mem: 3824 3714 110 0 142 2632
  3. -/+ buffers/cache: 939 2885
  4. Swap: 3490 0 3490

从顶部开始的内存使用情况:

  1. Mem: 3916648k total,3797056k used,119592k free,145820k buffers
  2. Swap: 3574452k total,168k used,3574284k free,2686844k cached

更新:昨天重新启动服务器,它在下午的剩余时间工作.然而,今天它正在做同样的事情.

运行“strace PHP test.PHP”(一个存在的文件),它会持续一段时间,但putty的最后一页左右是这样的:

  1. fstat(3,{st_mode=S_IFREG|0644,st_size=100030,...}) = 0
  2. mmap(NULL,100030,PROT_READ,MAP_PRIVATE,3,0) = 0x2ad3ce0af000
  3. close(3) = 0
  4. open("/lib64/libnss_dns.so.2",O_RDONLY) = 3
  5. read(3,"\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\17\0\0\0\0\0\0"...,832) = 832
  6. fstat(3,{st_mode=S_IFREG|0755,st_size=23736,2113792,PROT_READ|PROT_EXEC,MAP_PRIVATE|MAP_DENYWRITE,0) = -1 ENOMEM (Cannot allocate memory)
  7. close(3) = 0
  8. munmap(0x2ad3ce0af000,100030) = 0
  9. alarm(0) = 0
  10. futex(0x3d80e07b20,FUTEX_WAKE_PRIVATE,2147483647) = 0
  11. futex(0x3d80e079a0,2147483647) = 0
  12. futex(0x3d7fe94760,2147483647) = 0
  13. futex(0x3d7fe94c10,2147483647) = 0
  14. stat("/etc/krb5.conf",st_size=608,...}) = 0
  15. open("/proc/filesystems",O_RDONLY) = 3
  16. read(3,"nodev\tsysfs\nnodev\trootfs\nnodev\tb"...,4095) = 314
  17. close(3) = 0
  18. open("/etc/krb5.conf",O_RDONLY) = 3
  19. open("/proc/filesystems",O_RDONLY) = 4
  20. read(4,4095) = 314
  21. close(4) = 0
  22. access("/etc/krb5.conf",W_OK) = -1 EACCES (Permission denied)
  23. fstat(3,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x2ad3ce0af000
  24. read(3,"[logging]\n default = FILE:/var/l"...,4096) = 608
  25. read(3,"",4096) = 0
  26. close(3) = 0
  27. munmap(0x2ad3ce0af000,4096) = 0
  28. open("/dev/urandom",O_RDONLY) = 3
  29. fstat(3,{st_mode=S_IFCHR|0444,st_rdev=makedev(1,9),...}) = 0
  30. read(3,"\300\260\36co\363cI\t\355\324\3518gy\354\357\314Z:",20) = 20
  31. close(3) = 0
  32. futex(0x3d7f624640,2147483647) = 0
  33. open("/proc/filesystems",4095) = 314
  34. close(3) = 0
  35. open("/etc/krb5.keytab",O_RDONLY) = -1 ENOENT (No such file or directory)
  36. open("/proc/filesystems",4095) = 314
  37. close(3) = 0
  38. futex(0x3d8122d0c0,2147483647) = 0
  39. stat("/dev/urandom",...}) = 0
  40. brk(0x340b000) = 0x340b000
  41. brk(0x342c000) = 0x340b000
  42. mmap(NULL,1048576,0) = -1 ENOMEM (Cannot allocate memory)
  43. mmap(NULL,134217728,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE,67108864,0) = -1 ENOMEM (Cannot allocate memory)
  44. write(2,"Out of memory\n",14Out of memory
  45. ) = 14
  46. exit_group(1) = ?

编辑:按照sonassi的要求添加输出.

整个日志位于http://www.2shared.com/file/05MVRFI6/dmp.html

cat / proc / meminfo的输出

  1. MemTotal: 3916648 kB
  2. MemFree: 501180 kB
  3. Buffers: 335276 kB
  4. Cached: 2312536 kB
  5. SwapCached: 0 kB
  6. Active: 1312888 kB
  7. Inactive: 1702096 kB
  8. HighTotal: 0 kB
  9. HighFree: 0 kB
  10. LowTotal: 3916648 kB
  11. LowFree: 501180 kB
  12. SwapTotal: 3574452 kB
  13. SwapFree: 3574292 kB
  14. Dirty: 728 kB
  15. Writeback: 0 kB
  16. AnonPages: 367160 kB
  17. Mapped: 33640 kB
  18. Slab: 351564 kB
  19. PageTables: 18588 kB
  20. NFS_Unstable: 0 kB
  21. Bounce: 0 kB
  22. CommitLimit: 5532776 kB
  23. Committed_AS: 1188280 kB
  24. VmallocTotal: 34359738367 kB
  25. VmallocUsed: 265828 kB
  26. VmallocChunk: 34359471827 kB
  27. HugePages_Total: 0
  28. HugePages_Free: 0
  29. HugePages_Rsvd: 0
  30. Hugepagesize: 2048 kB

运行PHP test.PHP后cat / proc / meminfo的输出如下.我在这里替换了服务器的IP地址,因为它是公共IP – xxx.xxx.xxx.11是服务器的主IP,xxx.xxx.xxx.12是其他IP.

  1. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=3 ID=271 PROTO=UDP SPT=10170 DPT=33437 LEN=12
  2. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=89.39.188.210 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=117 ID=47199 DF PROTO=TCP SPT=2119 DPT=4899 WINDOW=65535 RES=0x00 SYN URGP=0
  3. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=89.39.188.210 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=117 ID=47678 DF PROTO=TCP SPT=2119 DPT=4899 WINDOW=65535 RES=0x00 SYN URGP=0
  4. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=89.39.188.210 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=117 ID=48675 DF PROTO=TCP SPT=2119 DPT=4899 WINDOW=65535 RES=0x00 SYN URGP=0
  5. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=198.60.169.59 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=116 ID=16299 DF PROTO=TCP SPT=3185 DPT=5555 WINDOW=16384 RES=0x00 SYN URGP=0
  6. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=198.60.169.59 DST=xxx.xxx.xxx.12 LEN=48 TOS=0x00 PREC=0x00 TTL=116 ID=16300 DF PROTO=TCP SPT=3186 DPT=5555 WINDOW=16384 RES=0x00 SYN URGP=0
  7. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=198.60.169.59 DST=xxx.xxx.xxx.12 LEN=48 TOS=0x00 PREC=0x00 TTL=116 ID=17038 DF PROTO=TCP SPT=3186 DPT=5555 WINDOW=16384 RES=0x00 SYN URGP=0
  8. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=198.60.169.59 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=116 ID=17073 DF PROTO=TCP SPT=3185 DPT=5555 WINDOW=16384 RES=0x00 SYN URGP=0
  9. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=188.254.224.225 DST=xxx.xxx.xxx.12 LEN=48 TOS=0x00 PREC=0x00 TTL=113 ID=39888 PROTO=TCP SPT=59828 DPT=5900 WINDOW=65535 RES=0x00 SYN URGP=0
  10. Firewall: *TCP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=188.254.224.225 DST=xxx.xxx.xxx.11 LEN=48 TOS=0x00 PREC=0x00 TTL=113 ID=43041 PROTO=TCP SPT=59828 DPT=5900 WINDOW=65535 RES=0x00 SYN URGP=0
  11. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=269 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  12. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=1 ID=269 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  13. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=2 ID=270 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  14. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=2 ID=270 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  15. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=3 ID=271 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  16. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=93.191.199.110 DST=xxx.xxx.xxx.11 LEN=32 TOS=0x00 PREC=0x00 TTL=3 ID=271 PROTO=UDP SPT=10202 DPT=33437 LEN=12
  17. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=65.111.170.208 DST=xxx.xxx.xxx.11 LEN=444 TOS=0x00 PREC=0x00 TTL=52 ID=0 DF PROTO=UDP SPT=5105 DPT=5060 LEN=424
  18. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=65.111.170.208 DST=xxx.xxx.xxx.12 LEN=443 TOS=0x00 PREC=0x00 TTL=52 ID=0 DF PROTO=UDP SPT=5105 DPT=5060 LEN=423
  19. TCP: Treason uncloaked! Peer 82.129.64.220:5306/59348 shrinks window 3410313698:3410313754. Repaired.
  20. Firewall: *UDP_IN Blocked* IN=eth0 OUT= MAC=00:23:ae:8f:59:78:30:37:a6:da:d2:e9:08:00 SRC=223.203.192.53 DST=xxx.xxx.xxx.12 LEN=1500 TOS=0x00 PREC=0x00 TTL=47 ID=2742 PROTO=UDP SPT=0 DPT=0 LEN=44665

cat /etc/security/limits.conf显示我已经注释掉了所有内容

  1. # /etc/security/limits.conf
  2. #
  3. #Each line describes a limit for a user in the form:
  4. #
  5. #<domain> <type> <item> <value>
  6. #
  7. #Where:
  8. #<domain> can be:
  9. # - an user name
  10. # - a group name,with @group Syntax
  11. # - the wildcard *,for default entry
  12. # - the wildcard %,can be also used with %group Syntax,# for maxlogin limit
  13. #
  14. #<type> can have the two values:
  15. # - "soft" for enforcing the soft limits
  16. # - "hard" for enforcing hard limits
  17. #
  18. #<item> can be one of the following:
  19. # - core - limits the core file size (KB)
  20. # - data - max data size (KB)
  21. # - fsize - maximum filesize (KB)
  22. # - memlock - max locked-in-memory address space (KB)
  23. # - nofile - max number of open files
  24. # - RSS - max resident set size (KB)
  25. # - stack - max stack size (KB)
  26. # - cpu - max cpu time (MIN)
  27. # - nproc - max number of processes
  28. # - as - address space limit
  29. # - maxlogins - max number of logins for this user
  30. # - maxsyslogins - max number of logins on the system
  31. # - priority - the priority to run user process with
  32. # - locks - max number of file locks the user can hold
  33. # - sigpending - max number of pending signals
  34. # - msgqueue - max memory used by POSIX message queues (bytes)
  35. # - nice - max nice priority allowed to raise to
  36. # - rtprio - max realtime priority
  37. #
  38. #<domain> <type> <item> <value>
  39. #
  40.  
  41. #* soft core 0
  42. #* hard RSS 10000
  43. #@student hard nproc 20
  44. #@faculty soft nproc 20
  45. #@faculty hard nproc 50
  46. #ftp hard nproc 0
  47. #@student - maxlogins 4
  48.  
  49. # End of file

而cat /etc/sysctl.conf的输出

  1. # Kernel sysctl configuration file for Red Hat Linux
  2. #
  3. # For binary values,0 is disabled,1 is enabled. See sysctl(8) and
  4. # sysctl.conf(5) for more details.
  5.  
  6. # Controls IP packet forwarding
  7. net.ipv4.ip_forward = 0
  8.  
  9. # Controls source route verification
  10. net.ipv4.conf.default.rp_filter = 1
  11.  
  12. # Do not accept source routing
  13. net.ipv4.conf.default.accept_source_route = 0
  14.  
  15. # Controls the System Request debugging functionality of the kernel
  16. kernel.sysrq = 0
  17.  
  18. # Controls whether core dumps will append the PID to the core filename
  19. # Useful for debugging multi-threaded applications
  20. kernel.core_uses_pid = 1
  21.  
  22. # Controls the use of TCP syncookies
  23. net.ipv4.tcp_syncookies = 1
  24.  
  25. # Controls the maximum size of a message,in bytes
  26. kernel.msgmnb = 65536
  27.  
  28. # Controls the default maxmimum size of a mesage queue
  29. kernel.msgmax = 65536
  30.  
  31. # Controls the maximum shared segment size,in bytes
  32. kernel.shmmax = 68719476736
  33.  
  34. # Controls the maximum number of shared memory segments,in pages
  35. kernel.shmall = 4294967296

编辑:更新上面的ulimit以dan,而不是root运行.

重新阅读上面的评论和原始帖子后 – 你以root身份运行ulimit -a – 但你说root不受影响.

这里的问题是ulimit,但是在用户级别.以dan用户身份登录并运行ulimit -a,您可能会发现内存有限.

猜你在找的PHP相关文章