I implemented a data structure making of nodes. Each node can get its child node or parent node.
I tried to test the data structure on my web server, and found its performance is awful.
below is the sample code.
class Node
{
public $next = null;
public $parent = null;
public function __construct($name)
{
$this->name = $name;
}
public function __destruct()
{
static $i = 0;
print_r(++$i.':'.$this->name.' '.date('H:i:s')."
");
$this->next = null;
$this->parent = null;
}
};
$root = new Node('root');
$curNode = $root;
$count = 10;
while (--$count) {
$curNode->next = new Node('node'.$count);
$curNode->next->parent = $curNode;
$curNode = $curNode->next;
}
print_r("end
");
return;
I ran it through web server and get the following result:
end
1:root 17:32:46
2:node9 17:32:46
3:node8 17:32:46
4:node7 17:32:46
5:node6 17:32:47
6:node5 17:32:47
7:node4 17:32:47
8:node3 17:32:47
9:node2 17:32:47
10:node1 17:32:48
It took almost 2 second just to destroy ten nodes. I can't find out the reason. I executed same code through cli, and it finished immediately.
My host runs Apache/2.4.29 and uses PHP 7.3.6. How can I fix it? Thank you.