Welcome Guest, Not a member yet? Register   Sign In
Use thread for send sms
#1

Hi
I send sms in my app via API
For send this sms,it take about 2 second
But i dont want to take it
So i want to use shell("php file.php") or thread
Do you have solution?
Reply
#2

(This post was last modified: 07-23-2018, 12:42 AM by Pertti.)

Depends how quick you want your texts to be delivered.

You could build AJAX solution, so the 2 second delay is masked.

If you are OK with texts taking a bit longer to deliver, you could set up a cron job to run every minute, keep queue of pending texts in DB, so response on website is instant, but it'll take up to a minute to fire off texts.

Your third, and most complicated option is to build persistent PHP script that keeps running and checking DB in shorter intervals (cron can only do every minute as shortest time-unit). That's the solution we use here, but it's a bit tricky, PHP sometimes can run out of memory, so I had to build in feature where we have monitoring cron job that checks scripts process is there every minute, and a shut-down point in script so if it's using too much memory, it'll close down and another process can be created by cron monitor script.
Reply
#3

(07-23-2018, 12:41 AM)Pertti Wrote: Depends how quick you want your texts to be delivered.

You could build AJAX solution, so the 2 second delay is masked.

If you are OK with texts taking a bit longer to deliver, you could set up a cron job to run every minute, keep queue of pending texts in DB, so response on website is instant, but it'll take up to a minute to fire off texts.

Your third, and most complicated option is to build persistent PHP script that keeps running and checking DB in shorter intervals (cron can only do every minute as shortest time-unit). That's the solution we use here, but it's a bit tricky, PHP sometimes can run out of memory, so I had to build in feature where we have monitoring cron job that checks scripts process is there every minute, and a shut-down point in script so if it's using too much memory, it'll close down and another process can be created by cron monitor script.

Cron Job execute every a minute at least and sms must be deliver in 2 minute so cron job is bad idea
Is it good curl_init for run special page for send sms?
Reply
#4

If you come through browser, it might make a bit difference, but really this is how it works:

1. User goes to a link in browser
2. Your PHP script starts
3. Your making CURL request to SMS providers API
4. ??? whatever their API needs to do
5. API responds to your request and your script can continue
6. You finalise HTML and serve it to user
7. User browser page finishes loading

However if it only takes 2 to 5 seconds, I really think you should look into AJAX solution

1. First page loads
2. User activates SEND SMS function
3. User stays on the page, you might show little loading animation, and AJAX request is made behind the scenes
4. All the steps from before happen on separate HTTP request
5. Response comes back from AJAX, you remove loading animation and display feedback on whether sending text was successful or not
Reply
#5

(07-23-2018, 01:19 AM)Pertti Wrote: If you come through browser, it might make a bit difference, but really this is how it works:

1. User goes to a link in browser
2. Your PHP script starts
3. Your making CURL request to SMS providers API
4. ??? whatever their API needs to do
5. API responds to your request and your script can continue
6. You finalise HTML and serve it to user
7. User browser page finishes loading

However if it only takes 2 to 5 seconds, I really think you should look into AJAX solution

1. First page loads
2. User activates SEND SMS function
3. User stays on the page, you might show little loading animation, and AJAX request is made behind the scenes
4. All the steps from before happen on separate HTTP request
5. Response comes back from AJAX, you remove loading animation and display feedback on whether sending text was successful or not

Thank your for your reply
Sorry but i use api in Android Application
I send request from app to api and api send sms to user
SMS api is Soap Protocol
Reply
#6

Ah right. Well in that case it's basically AJAX solution anyway Smile
Reply
#7

(07-23-2018, 01:55 AM)Pertti Wrote: Ah right. Well in that case it's basically AJAX solution anyway Smile

How do i use AJAX in app?
Reply
#8

(07-23-2018, 02:19 AM)omid_student Wrote: How do i use AJAX in app?

No I meant as in if you work with native app, all requests you do kind of work like AJAX, you stay on the page/view, but behind the scenes a request is made.

It really depends on native app framework you are using, and I really don't have any experience with any of them, but sounds like you want to find a solution that is non-blocking or runs on second thread so your main app can show the loading animation and not feel "stuck" while it waits response.
Reply
#9

(07-23-2018, 03:02 AM)Pertti Wrote:
(07-23-2018, 02:19 AM)omid_student Wrote: How do i use AJAX in app?

No I meant as in if you work with native app, all requests you do kind of work like AJAX, you stay on the page/view, but behind the scenes a request is made.

It really depends on native app framework you are using, and I really don't have any experience with any of them, but sounds like you want to find a solution that is non-blocking or runs on second thread so your main app can show the loading animation and not feel "stuck" while it waits response.

Yes i know but sms must be send from server not via mobile(application)
Thanks
Reply
#10

I have something similar in my application where i run SQL request and generate an xlsx file out of the result.

For me it works like this:

1, UI sends the query id or the sql via ajax to a back-end function
2 I have a worker daemon that receives the sql string and executes it and creates the xlsx file
3 The back-end uses zmq library to pass on the details and the sql string to the worker

The advantage for me is that i do not have to wait for the back-end tasks to complete to allow the user to navigate away from the page. It is a fire and forget solution.

If you have to provide a status for your sms, you could do get the worker in this case to update the DB with a success or failure status.

Also you could have a "fan" and multiple workers that could send the sms in parallel.

See this http://zguide.zeromq.org/php:all
Reply




Theme © iAndrew 2016 - Forum software by © MyBB