1

I am reading a large text value from MySQL and want to echo it in PHP.

The whole value is not being displayed.

I have manually exported and reviewed the cell in MySQL, and I can assure that the variable is fully stored in MySQL.

That means there is at least 1 of 2 problems.

The text is about 1MB long

1) PHP unable to echo more than X bytes.

2) PHP unable to read MySQL column and row over X bytes.

How should I approach solving this?

Lao Tzu
  • 759
  • 2
  • 6
  • 13
  • Possible duplicate of [Are there any length limits on PHP echo?](http://stackoverflow.com/questions/2273814/are-there-any-length-limits-on-php-echo) – WillardSolutions May 17 '16 at 13:41
  • Thanks for the resource. I have already checked that and I included it in my thread, "I have manually exported and reviewed the cell in MySQL, and I can assure that the variable is fully stored in MySQL." , perhaps you missed that. – Lao Tzu May 17 '16 at 13:43
  • 1
    What data type did you use to save the text in your database – Mueyiwa Moses Ikomi May 17 '16 at 13:44
  • longtext, the MySQL storage isn't the problem, it is either one of the two I already listed – Lao Tzu May 17 '16 at 13:45
  • @NickLim i'm pretty sure it's not either of the two possibilities you listed. please provide your code. – mister martin May 17 '16 at 13:50
  • Add a similar-ish problem with `var_dump`. I am really not sure the solution would have an impact on `echo`, but just in case... http://stackoverflow.com/questions/9998490/how-to-get-xdebug-var-dump-to-show-full-object-array – mokk May 17 '16 at 13:52
  • 1
    Longtext Holds a string with a maximum length of 4,294,967,295 characters. I doubt it's mysql then, gotta be php. Let's see some code please – Mueyiwa Moses Ikomi May 17 '16 at 13:52
  • What code do you need to see, and yes I already stated that earlier in the thread... – Lao Tzu May 17 '16 at 13:55
  • Mokk, I am also getting same problem on var dump, I think I have an idea why... testing rn – Lao Tzu May 17 '16 at 13:56
  • Well of course there is the **obvious PHP Limit** of the size you have allocated to `memory_limit` in the `php.ini` file. **Do you see any errors in the `php error log`** – RiggsFolly May 17 '16 at 14:02
  • Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly May 17 '16 at 14:06
  • Hello RiggsFolly, thank you for responding to the question. I have increased the memory limit to 512MB, prior to posting this thread as I thought that might be the problem. I also checked the logs and found nothing. – Lao Tzu May 17 '16 at 14:06
  • Did you edit the correct `php.ini` file? There are normally 2 one for PHP under Apache and one for PHP CLI – RiggsFolly May 17 '16 at 14:08
  • I already have enabled error_reporting ALL, and it yields nothing, what else can we try? – Lao Tzu May 17 '16 at 14:08
  • Yes, I am using PHP-FPM, so I edited the appropriate one in the FPM folding. Nginx -> PHP5-FPM – Lao Tzu May 17 '16 at 14:09
  • I just tried to echo the variable in chunks, still the exact same result. Leads me to believe there is a max variable size in PHP – Lao Tzu May 17 '16 at 14:28
  • Edit, I actually believe the problem is isolated to grabbing the variable from the database. – Lao Tzu May 17 '16 at 14:45
  • Isolate the code in a try/catch block if not done already. Immediately after the DB read, echo the strlen of the field. I just built a fairly accurate mock-up of your bizarre issue, works for me in all unit tests, except if i am reading in a browser with a timeout on the http get. Did you check all the logs i mentioned ? forgot to mention the db-log :) – YvesLeBorg May 17 '16 at 14:48

1 Answers1

1

PHP PDO has a maximum buffer attribute. You can change this with: $conn->setAttribute(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1024*1024*50);

Lao Tzu
  • 759
  • 2
  • 6
  • 13
  • This the answer, was tough to find it considering there is no documentation and the StackOverflow community did not respond well to this question even though it being so fundamental and having no answers. Hopefully, this helps a lot of people in the future! – Lao Tzu May 17 '16 at 14:51