suntrop Posted June 9, 2016 Posted June 9, 2016 I am using Sparkpost's API to send emails from a template file. Everything works good, but when it doesn't, it fails more than bad, because if I output the error message the server runs out of memory. No matter if I try to display it via print_r(), var_dump() or write to a file with var_export() and file_put_contents() If I disable Processwire's .htaccess and load the file directly (with some modifications to the code) I don't have that problem. The error message will be displayed without any problem. It isn't big < 10 kb In short this is my code <?php // Include SparkMail require 'vendor/autoload.php'; use SparkPost\SparkPost; use GuzzleHttp\Client; use Ivory\HttpAdapter\Guzzle6HttpAdapter; if ($input->post->mailing_submit && is_numeric($input->post->submit_verify)) { // Check for missing fields etc. // … CODE // If all required fields are set, go on if (empty($error)) { // Get recipients $recipients = $users->find($selector); foreach ($recipients as $recipient) { // … CODE } // Send email to users // render template for HTML mail body $httpAdapter = new Guzzle6HttpAdapter(new Client()); $sparky = new SparkPost($httpAdapter, ['key'=>'MYAPIKEY']); try { $results = $sparky->transmission->send([ 'from'=>[ 'name' => 'My Name', 'email' => 'info@example.com' ], 'html'=> $template_html, 'subject'=> 'My subject', 'trackClicks'=> 0, 'recipients'=> $address ]); $success['sent_admin'] = true; } catch (\Exception $spark_err) { echo 'Error: email not sent'; // print_r( $spark_err ); doesn't work => memory exhausted // var_dump($spark_err); doesn't work => memory exhausted $data = var_export($spark_err, true); // doesn't work => memory exhausted file_put_contents($config->paths->logs . date('Y-m-d') . "_sparkpost_error_member_mail.txt", $data, FILE_APPEND); die(); } // End send E-Mail to users } } using PW 3.0.18 with PHP 5.5 on Apache 2.2 Had posted this as an issue at the SparkPost Github repo, but no answer there and I think that has got something to to with PW.
flydev Posted June 9, 2016 Posted June 9, 2016 I want to think that your issue is related to your server's PHP configuration. What is the value of memory_limit in your php.ini file ?
suntrop Posted June 9, 2016 Author Posted June 9, 2016 I could test it on another server, but I don't think it is my configuration (which in particular was in your mind)? I am currently on a new vServer and limit is set to 256 MB.
LostKobrakai Posted June 9, 2016 Posted June 9, 2016 How about printing just the exception's message instead if the whole object? 3
suntrop Posted June 9, 2016 Author Posted June 9, 2016 Just parts of the exception are ok to log. I am new to Sparkpost's API and therefor I'd like to log it completely (preferably in one go) … without "disabling" PW to debug my errors :-D
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now