I need to generate and store a lot of small (1-10KB) PNG images (>10 millions) to the database. The only thing I care is images/s throughput. For now I know two ways of storing GD image object to the database:
Use output buffer:
ob_start();
imagepng($image);
$imageData = ob_get_contents();
ob_end_clean();
Use temporary file (tmpfs/ramfs):
$tmpFilePath = '/dev/shm/file_000.png';
imagepng($image, $tmpFilePath);
$imageData = file_get_contents($thumbnail);
Update. There is a 3rd method: Use PHP memory stream:
// PHP streams are NOT supported
$tmpFilePath = 'php://memory';
imagepng($image, $tmpFilePath);
$imageData = file_get_contents($tmpFilePath);
My question is are there any other ways to write image to DB? Any pros/cons of each method. Maybe it is worth to write a custom stream, which writes data to DB directly?
Note: Storing images to filesystem is NOT an option.