I'm having difficulties to view the return of Doctrines findBy() method.
The problem:
$res = $this->em->getRepository()->findBy(['deletedAt' => null], [], 10);
f($res);
As you can see, I limited the results to ten, so count($res)
gives 10. Also, the table that I'm fetching from here has only about 20 rows!
Now, this is the f()
function which I commonly use to use var_dump in Ajax requests.
function f($tx){
ob_clean();
ob_start();
echo "<pre>";
var_dump($tx);
echo "</pre>";
$var = ob_get_clean();
file_put_contents("d:/temp/f.html", $var, FILE_APPEND);
}
The error that is produced by this is:
[23-Mar-2018 14:43:25 UTC] PHP Fatal error: Out of memory (allocated 423624704) (tried to allocate 417349632 bytes) in D:\_webdev\rest-api-server\resources\config\default.php on line 8
where line 8
is the var_dump() line in the function f().
I already increased the memory limit in php.ini to 2GB. Also, there is many, many lines of this error per request(!). What in the world is going on the with return of findBy()? The doc of findBy() says:
Returns
array
The objects.
It is just 10 rows. What is consuming so much space? What objects are in the array?
An excerpt of the entity definition of the table I'm fetching from.
/**
* @ORM\Column(type="integer", length=11)
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="\App\Entity\User")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="CASCADE")
**/
protected $author;
/**
* @ORM\ManyToMany(targetEntity="User")
* @ORM\JoinTable(name="posts_attendees",
* joinColumns={@ORM\JoinColumn(name="post_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}
* )
**/
protected $attendees;
Those are three columns of roughly a dozen columns. Can the ManyToMany relations cause this? I'm not used to Doctrine Repositories. Normally I would understand the query returning a set of results, e.g. rows. But here the result of the 10 lines consume 2 GB of data. Wtf. It feels like each contain all users (>60k) or something ;) Why, on earth?
Edit (temporary solution)
I advanced the debug function by this. Not exactly what I was for, but at least it works.
function f($tx, $doctrine = false){
ob_clean();
ob_start();
echo "<pre>";
if($doctrine) \Doctrine\Common\Util\Debug::dump($tx);
else var_dump($tx);
echo "</pre>";
$var = ob_get_clean();
file_put_contents("d:/temp/f.html", $var, FILE_APPEND);
}
It shows me, that the result is an array of length 10 each containing an object of the fetched results. The types of the ManyToMany relations are Entity classes in itselft. No idea why they consume 2G, though. Time to learn doctrine... Or ban it, I guess.