In my PHP application, I receive mails using Postmarks's inbound hook. This service receives the mail and sends it JSON encoded to a URL on my server, which works fine.
The issue I have is, when the mail has attachments with more than 10MB.
Which results in
PHP Fatal error: Allowed memory size of 104857600 bytes exhausted (tried to allocate 1821693 bytes)
What I'm doing in this line is:
$in = json_decode(file_get_contents("php://input"));
I have two questions:
- Is there a way to do this more memory efficient?
- Why is it failing for 10MB mails, where the memory limit is actually 100MB? Does Base64 + JSON encoding produce an overhead which is 10 times bigger than the original size?
Edit after debuging with memory_get_usage():
Script start
47MB memory usage.
$in = file_get_contents("php://input");
63MB memory usage.
json_decode($in);
PHP terminates, due to memory size exhausted.
It is interesting, that the script already starts with a memory usage of 47MB, without issuing any command. I guess this is due to the large input data? Maybe because PHP stores it in $HTTP_RAW_POST_DATA?
Is there any php.ini directive I could use, to let PHP create less variables?