I'm working on a PHP website where when user selects city and submits the form, it will get the users phone numbers from the database for that particular city and sends SMS to them.
I have used cURL functions within a while loop to execute this and it is working fine.
NOTE: My sms gateway provider's API only support one number at a time per http request.
Now my question is if the number of user in the selected city is more than 10000 or 50000, then using cURL method will take much time to execute since it's in the loop? But the user wont like wait for the completion of loop. Is there any better way than doing this, like when user submits the request, something in backend (like job) will execute the function and even if the user closes the page, that job will execute till it completes the loop.
my solution was this:
--page /sendsms/?phone_nr=1122 sends one sms to phone nr 1122
--page /sendbulk has a loop which calls in php the page /sendsms/?phone_nr=1122 with file function file('http://www.domain.com//sendsms/?phone_nr=' . $phone_nr[$i]);
--the client on submit will call with ajax(no return needed) the page /sendbulk
This way even if the client closes the connection the server will continue to run /sendbulk in background and will send all messages
You can store detail of sms and city in another table, than set one Cron that take the all Number from the basis of City detail and Send To Sms Gateway , set that row as sent..
Related
I've created a system based on cron job which generates new tasks for user. When new task is generated cron file sends a sms to user using twilio sms api. Now I want make something like when user reply to that sms with word "Done" that task associated with sms will be completed in my database.
I've set reply URL in twilio account. And everything is working fine. My point is how can I complete that task in database. Is there any feature exist in twilio that can help me to send extra parameter as task id, so that I can fetch that id from reply and update the status of task.
Twilio developer evangelist here.
There's no way in SMS to reply to a specific message (try it yourself in your SMS app on your phone), so there's no ID that you can pass around secretly within conversations.
There are a few ways you can work around this.
If the user is sent only one task at a time, then you can record what their current task is and when you receive the message saying "done" tick that one off and send them the next task.
You could send them a task ID within the message, and tell them to include that ID when they respond to say they are done. You could then parse the ID out of the message and mark it as done in your database.
Or, and this might be too far, you could use a pool of numbers to send tasks out such that each live task for a user has a unique number the user responds to. Then you can look up the task based on the user and the number they replied to. Then you can free up the number for a new task.
Let me know if this helps at all.
I am trying to send an email to users based on their status. The first email needs to be sent after 2 hours, and a second one after 24 hours.
I am running a PHP script that checks for users who belong to a state and I sent the first email to them using the send API call, the problem now, is that when the script runs again (a crobtab that runs every 20 mins), I cannot send the campaign again since apparently you can send a campaign only once.
I am putting the cid directly in my PHP code, so I cannot go and edit the code everytime I want to run the crontab!
Do I have to use the campaigncreate()method everytime the crontab runs?
https://apidocs.mailchimp.com/api/2.0/campaigns/create.php
It would be better if there is an easier way, since an account cannot have more than 32,000 campaigns.
Mailchimp is a bulk email service and isn't designed to send transactional emails.
You should instead try to use Mandrill, a transactional email service built by the same company. And their API is quite simple to use.
Then, you can indeed run your PHP script every hour (or x minutes) to send emails based on user status.
I'm trying to develop a payment module for one shop cms.
Payment is based on acquiring in a Bank.
So firstly for each order creates (with curl) a "ticket" on bank side. Ater that client is forwarded on payment page on bank server with its ticket id. If customer pays and push button "go back to store" everything is fine.
But if customer pays and don't push this button i need to check the result (if he paid or not). It is also made by curl. I'm requesting info by ticket id and receive an array with parameters i need among them is result code i need to check.
So i need to check it automatically (for ex. 1 time each 5 mins during an hour).
Cron can't help me coz it is all dynamically processes.
I created a function that returns me the result. But how can i start it in background with any interval?
Using cron. PHP does not offer anything like scheduler because it is out of scope of the language. You may use DB to store some of parameters needed to the whole process.
I'll extend a little bit WebnetMobile answer on using cron for what you want.
Likely you have a table in your DB where you store are tickets you get from Bank and whenever they suceed or did not suceed as well the date the ticket was created.
Then, if what you want is to check every five minutes from bank ticket creation date whetever it suceed or not if unknown, you should run a cron each minute that will do the following:
Check if there are bank tickets without defined state (Suceed or Failed).
Check if time created (without seconds) minus current time (without seconds) MOD 5 == 0.
If true, means another 5 minutes period have passed from that ticket creation and should be checked, Else do nothing.
I think this will do what you want
Currently I have a script which processes orders after someone is directed to a payment processor.
The payment processor will occasionally send two (or more) responses to my site (usually within a minute of the first response).
I have contacted the payment processor about the issue; they don't see this as an issue with their system and say my script should take into account any extra responses and only listen to the last one sent.
On multiple response orders, the first response is successful, and so the order is processed when this response comes in.
If a 2nd response comes, its usually about 30 seconds later with an error response and I cancel the order.
The problem is that I have already sent out a "thank you for your order" email to the customer from the first response, which obviously isn't ideal.
Is there a way to trigger a separate script to run a few minutes after the order is processed? i.e to check if the order is still valid a couple of minutes after the original order and send the email out
I was thinking a cron job which runs every minute, but surely this would be overkill since the script only needs to run if an order has been placed?
You can start background job using shell_exec("/usr/bin/php /path/to/test.php ".($orderId)." &"); with 3 minute delay at the start (sleep(180)); and then execute code to check status of the order. $argv[2] should contain your orderId number.
Heres what you can do
after the first response is recieved, make your script wait for some time, say 1 minute using the sleep() function
http://php.net/manual/en/function.sleep.php
Why can't you change you message and notify a person with an email after second request came from your payment processor?
As I understand - your processor is already calling some URL on your site while sending second response. So that is a trigger you need. If they have no such callback functionality - you may just install some cron to which will go through not completely processed orders and check payment statuses for such orders and notify customer with another email.
My situation is that i have a page and the seller is going to take the order of a client, after the client orders, the seller hits the confirm button and awaits for the client to pass his identification card, wich i do with a ajax request and pop up a dialog with the list of products, a message and a cancel button.
After my ajax is sended in the server side, i'm doing a 'for' with a 'sleep' to check if the user has passed his card and then if he has, i put the items into his bill (persist into the database). The problem is, if that the user decides to cancel de proccess, i can't get the cancel ajax request to work because its busy with the first request on the server side and waiting its return.
Anyone have nay suggestions on that? I really wanted that the workflow of the site works like this:
Client orders -> Seller add the items and hits confirm -> Client passes confirmation or Seller can Cancel -> End of procces
Even if there was a simple way to do it the way you are going about it, this process would quickly overwhelm the server after more than a handful of connections.
I would store the customer's order to the database before requiring his identification, with a status field on the order set to "Awaiting Identification", or something to that effect. Then you can proceed with the identification flow without having to hold the PHP script waiting, and conserving a lot of resources.
If the client inadvertedly disconnects, you will still have saved her order and can allow her to complete identification at a later time.
Finally, when the client successfully completes identification, you can simply update the order 's status field to "authenticated" to indicate it's ready for processing.
EDIT: To address your particular problem, consider the following flow:
You save the order as "pending identification" and display the "Waiting..." dialog.
You perform a really simple request every few seconds asking whether the status of the order has changed, to know when the dialog needs closing.
At some point, the identification device sends a confirmation request upon which you retrieve the order and change its status. Then the periodic call you implemented in step 2 will kick in and hide the dialog.
The session is not a good location as a temporary storage medium, but a Redis, Memcached or similar service could help you simplify that process, given that the device and the site can in some way share information.