359 ini_set(
"memory_limit", -1);
360 if(!file_exists($outputFolder)){
361 mkdir($outputFolder, 0777,
true);
363 $this->server->getLogger()->notice(
"[Dump] After the memory dump is done, the server will shut down");
365 $obData = fopen($outputFolder .
"/objects.js",
"wb+");
367 $staticProperties = [];
375 $this->continueDump($this->server, $data, $objects, $refCounts, 0, $maxNesting, $maxStringSize);
379 foreach($objects as $hash => $object){
380 if(!is_object($object)){
385 $className = get_class($object);
387 $objects[$hash] =
true;
389 $reflection = new \ReflectionObject($object);
392 "information" =>
"$hash@$className",
396 if($reflection->getParentClass()){
397 $info[
"parent"] = $reflection->getParentClass()->getName();
400 if(count($reflection->getInterfaceNames()) > 0){
401 $info[
"implements"] = implode(
", ", $reflection->getInterfaceNames());
404 foreach($reflection->getProperties() as $property){
405 if($property->isStatic()){
409 if(!$property->isPublic()){
410 $property->setAccessible(
true);
412 $this->continueDump($property->getValue($object), $info[
"properties"][$property->getName()], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
415 fwrite($obData,
"$hash@$className: " . json_encode($info, JSON_UNESCAPED_SLASHES) .
"\n");
417 if(!isset($objects[
"staticProperties"][$className])){
418 $staticProperties[$className] = [];
419 foreach($reflection->getProperties() as $property){
420 if(!$property->isStatic() or $property->getDeclaringClass()->getName() !== $className){
424 if(!$property->isPublic()){
425 $property->setAccessible(
true);
427 $this->continueDump($property->getValue($object), $staticProperties[$className][$property->getName()], $objects, $refCounts, 0, $maxNesting, $maxStringSize);
432 echo
"[Dump] Wrote " . count($objects) .
" objects\n";
437 file_put_contents($outputFolder .
"/staticProperties.js", json_encode($staticProperties, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
438 file_put_contents($outputFolder .
"/serverEntry.js", json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
439 file_put_contents($outputFolder .
"/referenceCounts.js", json_encode($refCounts, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
441 echo
"[Dump] Finished!\n";