Forum Moderators: coopster

Message Too Old, No Replies

Sms - system messaging service

sending messages from one forum user to another

         

orion_rus

9:31 am on Nov 10, 2004 (gmt 0)

10+ Year Member



Hello everybody, i need your advices how to write sms service in the site.
All users who came to this site may exchanging an sms (write message and send it to server, server sends it to the other user)
Can u advice me the following steps:
1. How client knows when sms is arrives?
2. How i can create a new window and write a recieved text?
3. How i can store smses in the server side, if user offline in this moment.
Thanks for Help,
With best regards Alexey

baertyp

10:23 am on Nov 10, 2004 (gmt 0)

10+ Year Member



Alexey,

you will need to find and subscribe to an SMS gateway provider. The usual way is that after your subscription you get an interface description from the gateway people on how to send an SMS via your site and how to receive the answers in your site. Mine does this by calling a certain page on my site and sending the sms text and number in the URL as querystring which I in turn process using the $_GET superglobal. You can then do just about anything to alert the user of this incoming SMS - send a mail, send him an sms, ring his phone, whatever. This adresses topic 1 in your posting.

Topic 2: Opening new windows is a JavaScript issue, or just plain <a href="http://..." target="_blank"></a>

Topic 3: Your script which receivces the SMS should store them in a database, or, clearly second best, some form of flat file to present it to the offline users at their next visit to your site at a later time.

All in all this is not an easy task to accomplish, as you want to take approprate measures to avoid unauthorized people sending SMS through your system at their will. You will certainly have to pay for each SMS that you send via the gateway. Thus some sort of user authentication and SMS counter is mandatory, and once it's your money you should be very careful. Some SMS gateway providers let you place hard limits on how many SMS may be sent per hour/day/month. Consider placing reasonable limits even at the risk of your users not being able to send any more SMS once the limits are reached.

Regards
Markus

orion_rus

10:41 am on Nov 10, 2004 (gmt 0)

10+ Year Member



Thank u very much,
but i ask about system message service, not about mobile sms, but i very glad that u describe it how it works, thanks. I ask about a message, like u type in a textarea, and this message popup in the other browser of the user to which i send this information)

and what about database, where i can store it, because users can be about million and not best decision i think to place it in MySql. May be use DMB, or common files?
Thanks a lot for answer)

baertyp

11:40 am on Nov 10, 2004 (gmt 0)

10+ Year Member



Oh, indeed i got you wrong here. Well, knowledge is good at all times anyway... :-)

So you want your users to communicate trough a messaging system on your site.

Well, have the sender type the message and the recipient's name/id/nick/whatever in a form, process the form (validate input on server side!) and store the data into a database, together with all the necessary admin info such as timestamps and stuff. mySQL will do the job perfectly for most sites; you'll have to monitor the processes to see if it suits your specific needs. Averages of 100 queries/second and above are no real big deal for mySQL.

Next, incluce a snippet of code on every page your users can access, (something like 'include("messages.php")' ) which searches the database for new messages for the user. If there are any, you can present them to the user in the main window, or have PHP write the JavaScript code to open a pop-up window. Keep in mind though, that A LOT of users block pop-ups altogether, and that quite a few of them disable JavaScript completely.

You don't have to bother whether the recipient is online or offline, because he sees the messages the next time he hits one of your pages. You could of course check if the recipient is online at send time and send him an alert mail if he is not. Well, I guess you could do just about anything you want...

Happy messaging anyway.

Regards
Markus

orion_rus

6:40 pm on Nov 10, 2004 (gmt 0)

10+ Year Member



Thanks it's very helpfull information.
but how messages.php can always monitoring server state? which function i shall use?
if users were about million, i can't use mysql for saving messages i think, i think about dbm, or common files, where i can store it, what are u think about it?

ergophobe

7:29 pm on Nov 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Alexey,

PHP can't monitor the client state and can't create a pop-up. At best, PHP can have a "timeout" function so that anyone who has requested a page in the last X seconds will be considered online, but that's not a real time thing.

PHP also can't tell someone that a message has arrived. You will need a client-side program that periodically sends a request to the server to find out whether any message has come in. If it has, it could then open a window. Only at that point could a PHP script take over by requesting the message from the DB server.

baertyp

6:29 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Ergophobe is absolutely right here.

Either you decide that the user will be presented with his messages the next time he actively requests a page from your server, or you have some sort of background html document, say in an invisible (1px) frame or a blur()ed popup which requests the appropriate php script every n seconds using JavaScript or "META refresh" stuff which is considered a rather bad habit and can be turned off in several browsers, just like Java Script.

Remember how HTTP works: Client establishes connection to server, client requests document, server serves this request, connection is dropped. PHP is server side scripting and cannot actively open a connection to a client browser. The browser is simply not LISTENing on any ports on the user's machine. Any given firewall would be expected to prevent such a connection from the insecure outside anyway.

Any further approach into the "server push" technologies requires extra pieces of software to be installed on the user's machine to work as intended.

PHP can indeed monitor the server state, because it's running on the server. I can't see why you are voting against mySQL. Have a closer look at www.mysql.org and see what it was developed for. IMHO it seems the ideal tool for what you want to do. Some of my tables have far over 2M rows and there's nothing wrong with that. Keeping track of the user's last poll for messages is a simple task of UPDATEing the users table with a timestamp. Comparing this timestamp to the timestamp of the user's messages is just as easy and can be done in a single SQL query. www.php.net gives you all the information on which functions to use.

Thorough database design in the first place rewards your spent hours with scaleability and constantly good perfomance over time. Advice on this goes far beyond the scope of this forum though. There are quite a lot of resources on this topic. (Google for Entity Relationship Models, DB normalization, DB Indices, SQL queries using JOINS, etc.)

Regards
Markus

orion_rus

7:16 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Thank u very much, but this opens another some questions in my mind, Can u answer it too?
1. Ofcause i can use something like SetInterval() in a client site for making a process to access a server and ask him about sms arriving? but what function i should use to access on it, i don't know this function yet( ofcourse i can use a javascript to open a window. I understand what nothing else can open it, but how i moved a data where, i see it. But i don't think i can find a procedure what see a server condition and make monitoring server state(?
About tables. Let's i describe what i have, about 1-2 Million users in a perspective, all of them will have a contact list, about 5 thousands of hotels and about 1 thousand of wonders, any user can make a contactlist, with not more when 20 users it, it seems like database would be 2 million rows only for users and they contactlist would be about in 10-20 million savings. Shall i still store it in MySql, or make an a directory for each user(i don't know how file system will feels about it) and save their state in the local database dbm?
Thanks for helping my stupidity)
With Best Regards Alexey

baertyp

8:52 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Orion,

please forgive me if I am wrong, but from your questions i take it that you are not the most experienced programmer. [php.net ] is one of the best sites I have seen for ages in terms of documentation availability. Probably all of your questions will be answered there, at least all of mine have been so far. If it doesn't help you, you are most likely lacking the conceptual approach of software design.

As Mincklerstraat stated in your other thread in this forum [webmasterworld.com ] you should start off with a much, much less complex project involving database manipulation to get the feel of how get things straightened out.

Projects in the dimension you outlined in your postings are by far out of reach for someone who doesn't know how to query a database or how to produce any given output to a client.

Sorry, but my help must end here.

Regards
Markus

orion_rus

10:04 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Markus you are absoulutly right what i'm not experienced in php, i don't know this language even on three mark. I'm reading a books for it, but in Russia many books for PHP makes from one with some changes material, and what book doesn't briliant, what's why i can't see the information what i need. I'm already said you what i need to know, is any possibility make a form where client listens server and popups any event on it. I'm already understand what i need to reload page, where i would have a script which sees is sms arrive or not, if its arrive i popup window, or nothing.
Thank you for help, it was brilliant to me. I'm sorry if my stupidity uppsets you or something like it. I wants only exacts some things, what i can't find in our books. In the other words, i have leackages in some terms. You right. I hope i stopped it soon)

ergophobe

4:21 pm on Nov 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Alexey,

Have you downloaded the Windows Help (.chm) version of the manual in Russian yet? Books are fine of course, but I mostly learned PHP from the manual and this forum. This forum doesn't have a Russian translation yet, but the manual does:

[php.net...]

[us2.php.net...]

Cheers,

Tom

orion_rus

4:57 pm on Nov 12, 2004 (gmt 0)

10+ Year Member



Thank you for helping me, i'm of cause would be learn any new information from forum and tutorials in the site. I need to build my project for a month, how are u think is it real to make travel site for 1 month?
Thank you
With best regards
Alexey