set_memory_limit_003.phpt 875 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Test V8::setMemoryLimit() : Memory limit can be imposed later
  3. --SKIPIF--
  4. <?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $JS = <<< EOT
  8. var jsfunc = function() {
  9. PHP.imposeMemoryLimit();
  10. var text = "abcdefghijklmnopqrstuvwyxz0123456789";
  11. var memory = "";
  12. for (var i = 0; i < 100; ++i) {
  13. for (var j = 0; j < 10000; ++j) {
  14. memory += text;
  15. }
  16. sleep(0);
  17. }
  18. };
  19. jsfunc;
  20. EOT;
  21. $v8 = new V8Js();
  22. $v8->imposeMemoryLimit = function() use ($v8) {
  23. $v8->setMemoryLimit(10000000);
  24. };
  25. $func = $v8->executeString($JS);
  26. var_dump($func);
  27. try {
  28. $func();
  29. } catch (V8JsMemoryLimitException $e) {
  30. print get_class($e); print PHP_EOL;
  31. print $e->getMessage(); print PHP_EOL;
  32. }
  33. ?>
  34. ===EOF===
  35. --EXPECTF--
  36. object(V8Function)#%d (0) {
  37. }
  38. V8JsMemoryLimitException
  39. Script memory limit of 10000000 bytes exceeded
  40. ===EOF===