set_memory_limit_003.phpt 935 B

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