2

I'm using Iron.io push queues. Please explain what happens with attachments if I use code like this:

Mail::queue( 'email', array('body' => 'msg body here'), function($message) {
    $message
        ->to('email@gmail.com')
        ->subject('Subject')
        ->attach(storage_path() . '/file.mp4' );
});

If the file is small ( < 100 KB ) then request to such a page seems to be really quick. If the file is 5MB or so, then the request takes a couple of seconds. Therefore it looks like Laravel serializes attachments, sends them to Iron server, then Iron sends it back to my server and then email is finally sent. Is that true?

That's not what I expect from queues. I expect immediate response to user. I'm totally sure that sync driver is off and app uses iron, since I see messages in iron.io dashboard.

By the way, I'm using ngrok tunelling to work with queues on local dev machine. Maybe thats the cause?

  • That's not how I understand Iron.io. Your job should be queued locally and a request sent to Iron.io's servers to hit your endpoint to actually process the job. This happens outside of the page load (with the initial request to Iron.io being the only network request processed as part of the user's page load). The whole message shouldn't be sent to Iron otherwise it's susceptible to timeouts and defeats the whole point of queuing. – Martin Bean Jun 23 '15 at 10:07
  • Yes, I agree. But then, if I want to send message with 30MB large attachment, where these 30MB live while requests fly from myApp->Iron->myApp ? Probably the file is saved in some temp directory? – user5023350 Jun 23 '15 at 10:19
  • I’m not sure without digging into the source code for Laravel, but it shouldn’t go out to Iron. All that Iron should receive is a reference to the job, which in turn will execute a HTTP POST request to your app saying, “That email you have queued, send it.” – Martin Bean Jun 23 '15 at 11:15
  • I don't think Mail::queue goes out to IronMQ does it? Queue::push does? – Travis Reeder Jun 23 '15 at 17:00

1 Answers1

1

I'm not sure Mail::queue goes out to IronMQ, but if it does, I think you'd want to set it up in a way that the body does not get sent with it.

Instead of queuing the mail, queue up the metadata for the email, eg:

Queue::push(new SendEmail($message, $filepath));

Then when the push comes back to your app, SendMail can call the synchronous send mail:

Mail::send( 'email', array('body' => 'msg body here'), function($message) {
    $message
        ->to('email@gmail.com')
        ->subject('Subject')
        ->attach(storage_path() . $filepath );
});

I'm not a PHP person so the code may be a bit off, but it should convey the idea.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Travis Reeder
  • 38,611
  • 12
  • 87
  • 87