[eluser]rei[/eluser]
okay sir thanks, I will try to put some benchmark points in the code later.
nwei here is the source:
Code:
function eager()
{
// eager load
$users = User::find('all', array('include' => array('posts' => array('comments' => array('blogs')))));
foreach ($users as $user) {
echo 'User Name: ' . $user->name;
echo '<br>';
foreach ($user->posts as $post) {
echo 'Post: ' . $post->content;
echo '<br>';
//print_r($post->comments);
foreach ($post->comments as $comment) {
echo 'Comment: ' . $comment->comment;
echo '<br>';
foreach ($comment->blogs as $blog) {
echo $blog->name;
}
}
}
}
}
function lazy()
{
// lazy load
$users = User::find('all');
foreach ($users as $user) {
echo 'User Name: ' . $user->name;
echo '<br>';
foreach ($user->posts as $post) {
echo 'Post: ' . $post->content;
echo '<br>';
//print_r($post->comments);
foreach ($post->comments as $comment) {
echo 'Comment: ' . $comment->comment;
echo '<br>';
foreach ($comment->blogs as $blog) {
echo $blog->name;
}
}
}
}
}
I'm using PHP Active Record. and I'm only benchmarking this in my laptop localhost. xampp server