Jump to content

Memory exhausted, because of exception error


suntrop
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...