3

I'm using SMTP module to send e-mail messages after creating nodes. It takes about 3-4 seconds to send each such message using hook_node_insert. So if I want to send 10 messages, then I have to wait for 30-40 seconds for the iteration to complete and then only I get redirected to create new node. It's very slow.

I tried use event KernelEvents::TERMINATE per this article, but it did not speed up the whole process.

Is there a way just to complete creating a node without waiting and immediately proceed to creating a new node, while sending e-mail messages at the same time?

Note: I don't want to create queue and wait for the next cron run to send e-mails. Because e-mails need to be sent instantly after creating respective node

4
  • Use Rule's After saving new content action.
    – AltaGrade
    Commented Apr 4, 2018 at 3:47
  • Did you try it? I'm checking code, It's the same. Because they using hook_entity_save to dispatch action.
    – Jonh
    Commented Apr 4, 2018 at 7:46
  • It's really your call to try. But I know the event_dispatcher works seamlessly, so things should go smoother for you.
    – AltaGrade
    Commented Apr 4, 2018 at 9:29
  • 1
    Rules is an extra performance it. It is using event_dispatcher to react to events, which Kernel::TERMINATE is an event being dispatched by HttpKernel. Commented Apr 4, 2018 at 12:25

1 Answer 1

2

As noted on the Reddit thread, this event will not work as described in this blog unless you are using PHP FPM. For most hosting providers this is the default setup. So, if you are using Apache with mod_php you are out of luck, it seems.

Are you hosting with Apache and mod_php? You'll need Apache and use PHP FPM with some settings changed. Or use nginx.

Sounds like the problem is due to your server not streaming the output. Per the Symfony docs

Internally, the HttpKernel makes use of the fastcgi_finish_request PHP function. This means that at the moment, only the PHP FPM server API is able to send a response to the client while the server's PHP process still performs some tasks. With all other server APIs, listeners to kernel.terminate are still executed, but the response is not sent to the client until they are all completed.

https://symfony.com/doc/current/components/http_kernel.html#the-kernel-terminate-event

2
  • I don't see referenced link has anything to do with the question asked. Anyway, please note that answers should be relevant and not mislead other problem seekers for the same issue.
    – AltaGrade
    Commented Apr 4, 2018 at 15:25
  • Based on Is there a way just to complete creating a node without waiting and immediately proceed to creating a new node, while sending e-mail messages at the same time? it sounds like the OP's server is just not buffering as expected. Commented Apr 4, 2018 at 15:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.