The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Run code after response is displayed

Phil's Avatar

Phil

03 Oct, 2015 05:10 PM

I am writing an JSON REST API server with Slim for a mobile app that sends SMS notifications everytime a new user registers.
The SMS part is slow, and the client has to wait until the SMS completes until he gets the JSON response.

Is there any way of returning the JSON to the client and then calling the code that sends sms?

I've tried using hooks and middleware, but that didnt help, i still had to wait for the SMS code to complete until i got the JSON response.

  1. 1 Posted by Diego on 03 Oct, 2015 09:10 PM

    Diego's Avatar

    I would save the instructions for later (in a file or database) and have a cron job sending the sms in paralel

  2. 2 Posted by marco on 04 Oct, 2015 09:22 AM

    marco's Avatar

    As Diego recommended, I would disconnect the Web response from the blocking operation. I would use queues in this case (0mq, beanstalk, etc) with an SMS worker program that polls requests off the queue and processes them.

  3. 3 Posted by Phil on 04 Oct, 2015 08:58 PM

    Phil's Avatar

    In the end i solved it like you suggested.

    Thanks for your help!

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac