I have a website where users can register using their mobile number and the registered user get a text message confirming the registration. The page uses php. The mobile number gets stored as a variable $mobile.
The API for sending sms to the registered user is http://someurl/&message=[xxxx]&numbers=[xxxxx]
I want to execute the API in the background. I need to know a way to pass the number stored in $mobile variable to the API's url?
If the remote site responds fast you might try it synchronously: just call something like this:
file_get_contents(
sprintf('http://someurl/&message=%s&numbers=%s',
urlencode($message),
urlencode($mobile)) );
But usually it is more safe to perform such tasks independant from processing your registry step. Then you have to store that $mobile number somewhere. Probably you store the users profile data in a database. Also store a flag (marker) that the user has not yet been sent his message.
In addition you configure a cron job to call a script that does nothing but sending overdue messages on the server. It queries the database for any user profile that contains the flag indicating that the message has not yet been send and performs the same command as above.
The advantage: the user gets his feedback of registration right away, even when the sms gateway is down or busy. The message gets send a few seconds or a minute after the registration has completed. Such architecture is usually fast enough and much more stable.
Related
Currently there is an IT system with a web interface (login with user ID and password), where you login and then update some data.
Users receive an email from another IT system (written in PHP), with a request to manually enter the data into the first IT system.
I was thinking it may be possible to write a simple robot in PHP which automates this procedure of logging into the first IT system and updating the data.
The robot would be implemented in the second IT system and use the CURL library to login and make the changes (using HTTP, with GET and POST requests).
But to do this I need to understand how the login and data update works in the first IT system, because after the first (simple) login mask which generates a POST request, things get complicated: there is a Javascript dialog and it's a bit difficult to understand what happens next.
Is there a way to log and make visible all HTTP communication with the first IT system? With that I mean obtain the following:
I use a browser to log into the first system and make the edits/changes.
The logger runs in parallel and in the end shows which GET and POST requests and parameters and their values were sent and to which URLs
Let's say we have a system that needs to validate data using a third party system. For example, we allow user registration and we validate the provided email address using an external system that tell us if the email is valid, if it is a temporary email etc, etc.
Our system receives the email address, makes a request in real time to the third party email validation system and, depending on the response (email valid or not) it will allow the user to register.
My question is: What happens if something goes wrong with the connection? (timeout, DNS errors, etc). I think it will be wrong to allow the user to continue the registration process because we don't know if the email is valid but, at the same time, we can't stop the registration process because the email might be valid.
I'm thinking in trying the connection more than once (let's say, three times). If it fails, then return an error code with a message like "Please try again later". Is this the right approach to this problem?
Thanks in advance :D
You treat this the same way as if any other sub-system on the server failed, e.g. the database being down: 500 Internal Server Error or 503 Service Unavailable. Whether you want to try more than once before giving up is up to you.
It all depends on what kind of system you are working with. If you are confident that the Users will definitely comeback to your site later and register this approach is fine.
But in Today's world there are so many web services out there and the users are great assets, you wouldn't want to loose them or their data. You can always collect the data and store it in a staging table and later if you can run some Schedules tasks every 5 mins or add them to a queue service to validate the data with this 3rd party and finally store it in appropriate way and send them a notification about their account being active. This way the User experience when they use your web page will be great and they would come back (a second win is you can actually verify their email account)
Goal:- Inserting messages in faster way to database.
I have integrated xmpp openfire one-to-one chat over my website.
I am using Monitoring Service plugin for storing messages into the database.
What i am facing is when user send a message from one user to another user at that time messages are stored in the database.
Now messages are stored, but i am facing issue of inserting messages late into the database.
I am loading messages via ajax call when user clicks on another user message thread but if the messages does not store in the database ofcourse it will not be returned in ajax call history.
I have done following configuration settings for Monitoring Service plugin.
I've find alternative solution of modifying Monitoring Service plugin's jar file and decrements inserting seconds but ultimately it will affect database.
Eg. Every minute 50 users send 10 messages at that time database may hanged.
Any help would be appreciated if i can store the messages into the database as faster way!
I am building a Mobile Application (Phone, Jquery Mobile) for Android.
It requires a user sending a message to the server side script using an Ajax request. I implemented a system such that messages sent are not sent immediately, instead they are stored in a SQLite database (this is so because, I want the user to think the message is sent even if the network is bad) and an iteration that runs every 15 seconds in the background picks it up and send it. So therefore, if 5 messages are in the SQLite database, they will be sent every 15 seconds apart.
The above system works fine when I tested it with my Android phone connected to my WAMP via Wi-Fi.
The problem I now foresee is that when I deploy on a production Server, the Ajax response from the server won't be that fast.
Is there a way to avoid a potential problem?
Note: The response from server is via json and it is essential because it will be used to delete the message from the phone SQlite Database.
Here is how I read your question:
A user interacts with the app and this generates actions that need to be updated on your backend. (for example, "like a post", "upvote a coment" etc.)
You have decided that the action does not need to complete synchronously and that the user does not need to wait around for the action to be completed/acknowledged; The user can continue on with new actions. At some point, the user will see that the actions have been processed but immediate updates aren't important.
Your polling loop in the app is responsible for eventually sending the actions to the backend to be completed. The backend acknowledges the action has been completed by sending a response back to the app to delete the pending action.
My answer based on above:
Since it is the app waiting on your custom protocol to complete and not the user waiting on a synchronous action to complete, you have a lot of flexibility in the server's response times.
More important is that your little protocol makes sure to eventually process the action on the backend and notify the client app. You are dealing with the concept of things becoming "eventually consistent" and thus you need to design your little protocol around that:
http://en.wikipedia.org/wiki/Eventual_consistency
I have a registration form on my site. The form is sent to the server via AJAX and is then validated. Then it will output an address for the browser to be redirected to, if it was validated as valid information. PHP will then send a validation email to the email specified. The problem is that the sending of the email takes 10 seconds, and I don't want my users to wait for 10 seconds from they press Register to they get redirected...
Is there a way for PHP to tell the client the information was correctly validated and output the redirection URL, and continue sending the email without the client waiting?
It's called a background job.
To do this in the simplest way (note: not the best, but the simplest):
I'm assuming you're storing your registration details in some form of database. Add an extra column to flag that you need to send the validation email to this user.
In another script, check the database for any rows with this flag set, and send the email from there.
This second script will be triggered by a cronjob or similar, on a schedule of your choosing.
This way, users don't need to wait for that 10 seconds.
There are more efficient solutions that will cope better for larger scale sites, but I'm guessing that you don't yet need to know this, and that if I brought them into the equation it'd confuse matters. Look into Job Queues, if you want to know more.