Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
PHP select longblob memory issue

I'm trying to select data from a mysql LONGBLOB field, but the memory usage seems to grow out of control. I've tried with PDO and mysqli. (no problem inserting the data)

<?php
$path = 'test.txt';
$pdo = new PDO('mysql:host=localhost;dbname=db', 'user', 'pass');
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, TRUE);
$stmt = $pdo->prepare("select contents from files where path = :path limit 1");
$stmt->bindValue(':path', $path, PDO::PARAM_STR);
$result = $stmt->execute();
$stmt->bindColumn(1, $data, PDO::PARAM_LOB);
$result = $stmt->fetch(PDO::FETCH_BOUND);
var_dump(strlen($data));
var_dump(memory_get_peak_usage());

The output when running that is:
int(198608116)
int(1902241376)

so the column is 198.61MB, but the scripts memory usage reaches 10 times that 1,902.24MB.

Any idea what I am doing wrong?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!