bug55509.phpt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. --TEST--
  2. Bug #55509 (segfault on x86_64 using more than 2G memory)
  3. --SKIPIF--
  4. <?php
  5. if (PHP_INT_SIZE == 4) {
  6. die('skip Not for 32-bits OS');
  7. }
  8. $zend_mm_enabled = getenv("USE_ZEND_ALLOC");
  9. if ($zend_mm_enabled === "0") {
  10. die("skip Zend MM disabled");
  11. }
  12. if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
  13. // check the available memory
  14. if (PHP_OS == 'Linux') {
  15. $lines = file('/proc/meminfo');
  16. $infos = array();
  17. foreach ($lines as $line) {
  18. $tmp = explode(":", $line);
  19. $index = strtolower($tmp[0]);
  20. $value = (int)ltrim($tmp[1], " ")*1024;
  21. $infos[$index] = $value;
  22. }
  23. $freeMemory = $infos['memfree']+$infos['buffers']+$infos['cached'];
  24. if ($freeMemory < 2100*1024*1024) {
  25. die('skip Not enough memory.');
  26. }
  27. }
  28. elseif (PHP_OS == 'FreeBSD') {
  29. $lines = explode("\n",`sysctl -a`);
  30. $infos = array();
  31. foreach ($lines as $line) {
  32. if (!$line){
  33. continue;
  34. }
  35. $tmp = explode(":", $line);
  36. if (count($tmp) < 2) {
  37. continue;
  38. }
  39. $index = strtolower($tmp[0]);
  40. $value = trim($tmp[1], " ");
  41. $infos[$index] = $value;
  42. }
  43. $freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize'])
  44. +($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize'])
  45. +($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']);
  46. if ($freeMemory < 2100*1024*1024) {
  47. die('skip Not enough memory.');
  48. }
  49. } elseif (PHP_OS == "WINNT") {
  50. $s = trim(shell_exec("wmic OS get FreeVirtualMemory /Value 2>nul"));
  51. $freeMemory = explode('=', $s)[1]*1;
  52. if ($freeMemory < 2.1*1024*1024) {
  53. die('skip Not enough memory.');
  54. }
  55. }
  56. ?>
  57. --INI--
  58. memory_limit=2100M
  59. --FILE--
  60. <?php
  61. $a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
  62. echo "1\n";
  63. $a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
  64. echo "2\n";
  65. $a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
  66. echo "3\n";
  67. $a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
  68. echo "4\n";
  69. $a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
  70. echo "5\n";
  71. ?>
  72. --EXPECTF--
  73. 1
  74. 2
  75. 3
  76. 4
  77. Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d