Retrieve BLOB MySQL PHP issue when the data is transmitted through web server firewall
We are facing a critical issue with BLOBs being retrieved from MySQL DB using PHP and transmitted through the firewall. Same PHP code works fine when the DB is hit directly from localhost bypassing the web tier.
To elaborate the issue -
We have BLOBs stored in the MySQL DB which are retrieved using simple PHP code which works fine on Godaddy Shared Hosting. We recentl开发者_高级运维y moved to Amazon EC2 / RDS where firewalls are setup and we are noticing this issue that the PHP code retrieves correct BLOB but junk BLOB data is received with the response that comes from Apache through firewalls. The same code when connects directly to RDS and pulls the same BLOB it is retrieved and displayed just fine.
The code that stores the BLOB in the database has worked before and works fine now since the images being stored can be directly accessed using DB Connect.
I am so lost on this one as to why when the BLOBs come out through the web server as a part of the response just shows junk. I have tried adding headers etc. and everything nothing works when the response is through the Web Servers. I don't think the issue is with the PHP code that stores and retrieves the BLOBs to and from MySQL.
Can there be a firewall settings or Apache config on EC2 that can corrupt the BLOB data being transmitted? Please help.
From what you post in your question this looks like an encoding issue between the database client (your webserver) and the database server (amazon EC2). Just double-check the database client and server settings and ensure that the data stored within the database is correctly encoded as well.
I write so because the query gets through, only the BLOB data get's mangled. So this does not look like a firewall issue to me.
More information and links are available in the similar issue.
WOW!! This was a tough nut to crack but really incredible that this can mess up a working codebase.
In my PHP code that retrieves the BLOB I had the db connect string which i replaced with an include "DBCon.inc" and I put the db credentials in that file.
Guess what...the DBCon.inc file had two blank lines or something like that in it before the PHP end ?>
So the response to the GET that responds with the BLOB was getting appended with the two blank lines and the BLOB data was getting messed up and the browser was not being able to render the image anymore.
Removed the blanks in this file and Voila!! everything works just as it did before.
精彩评论