473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Regularly poll server for messages

6
Hi there,

I'm writing a PHP web app that sends and recieves sms text messages. I need to regularly poll the server for new incoming messages. I say regularly but it would be all the time really, every second or two, 24/7. Clearly this is outside of PHP's normal usage. Do you have any suggestions about the best language to use for this kind of action?

Thanks in advance,
Paul
May 16 '07 #1
9 1699
devsusen
136 100+
Hi,

U can do this using php. U need to do a script that will poll the server for new incoming message. Now u need to call the script in cron job in Apache server. Ur server must support the cron job and ur code should be highly optimised that it shouldn't take more than 1 sec. Then u can set the cron job to run every 1 or 2 sec.

Another way of doing this job is to use a shell script, though I am not very much familiar with shell script.

Hi there,

I'm writing a PHP web app that sends and recieves sms text messages. I need to regularly poll the server for new incoming messages. I say regularly but it would be all the time really, every second or two, 24/7. Clearly this is outside of PHP's normal usage. Do you have any suggestions about the best language to use for this kind of action?

Thanks in advance,
Paul
susen
May 16 '07 #2
Motoma
3,237 Expert 2GB
devsusan is spot on about setting up a cron job to perform this. Is there a reason why you would like to do this in PHP as opposed to some other technology?
May 16 '07 #3
c1pkw
6
Thanks devsusan and Motoma,

I've no problem with contacting the server with PHP but it is getting this script to run automatically every second or whatever that I wasn't sure about.

The reason for me wanting to use PHP is simply that other than vb and a bit of javascript, it's the only language that I'm that confident in. I'm just a hobbyist really. I have to admit that I'm not sure what a cron job is yet! but I'll soon find out.

I'd put together an alternative solution using javascript before I visited the forum. All it does is, every few seconds, refreshes the php page that polls the server. It seems to work well but I'm pretty sure that the server would get sick of it and deny service after a while.

Thanks for your help, any other ideas are certainly appreciated.

Yours,
Paul.
May 16 '07 #4
Motoma
3,237 Expert 2GB
cron is a service which runs on most *nix servers. If you are using a Windows server, the tool you would be looking for is AT. These are both utilities which provide scheduling for processes.

In order to run your PHP update script, you will call your PHP script from the command line: php -e /path/to/my/script.php

However, it sounds like it will be slightly more work from the way you make things sound.

This method will only work if you are keeping track of the data somewhere on the server. My intention (and devsusan's too, I am sure) was that your php script would gather information and then load that into a database. When your users go to view their messages, they would visit a different link that would then retrieve the information from the database.

If this is not the situation you are trying to obtain then I think we have had a miscommunication.
May 16 '07 #5
c1pkw
6
Hi Motoma,

I think we are talking about the same thing. I only need something to schedule and repeat the execution of my php script which, as you say, would collect incoming information and write it to the database. Users would then have an up to date record of their messages read back out from the database by various other php pages whenever they log on to the application.

The only concern that I have is that I usually host web apps on commercial shared webspace. I'm not sure that I wil have the authority to run a cron job on it so I will probably have to set up my own webserver. I'm not concerned about setting up a machine with Linux (probably Ubuntu) and Apache but I've never tried to make my webserver available any more widely that my LAN. I think I might have a lot of reading to do!

Yours,
Paul.
May 16 '07 #6
c1pkw
6
Great news! my hosting company say that I have privileges to run cron jobs! Woo hoo!
May 16 '07 #7
Motoma
3,237 Expert 2GB
Glad to hear it! Come back any time if you need help.

Great news! my hosting company say that I have privileges to run cron jobs! Woo hoo!
May 16 '07 #8
devsusen
136 100+
thats a gr8 news. But c1pkw please take care of your script so that it should take less time to get executed.

I have experienced some problem in running cron jobs in frequency less than a minute. Once your code takes more time to execute then what happen before completing one cron thread Apache starts another cron thread. This way if the number of running cron threads increases then the site start taking more server resources. This is a problematic situation for a site if its hosted in a shared server. Many third party hosting company setup their Apache in such a way that if a site starts consuming more resources then Apache will stop that specific service for that site.

Motoma if have such experience please share with us, cause I am also interested to know if this sort of situation can be avoided or not.

susen
May 22 '07 #9
Motoma
3,237 Expert 2GB
thats a gr8 news. But c1pkw please take care of your script so that it should take less time to get executed.

I have experienced some problem in running cron jobs in frequency less than a minute. Once your code takes more time to execute then what happen before completing one cron thread Apache starts another cron thread. This way if the number of running cron threads increases then the site start taking more server resources. This is a problematic situation for a site if its hosted in a shared server. Many third party hosting company setup their Apache in such a way that if a site starts consuming more resources then Apache will stop that specific service for that site.

Motoma if have such experience please share with us, cause I am also interested to know if this sort of situation can be avoided or not.

susen
To clarify, cron is run by the cron daemon (the crond process), not Apache.
Yes, Susen, this definitely can become a problem. Typically, the solution to a problem such as this is an object called a semaphore. In the simple case you would design a script that tests to see if a pid file exists, and if it does it will quit immediately. If it doesn't, the program will create it, run, and then delete the file. This will prevent your script from having more than one instance running at once.
May 22 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: JDJones | last post by:
I'd like to put up two polls on my web site on a single page. I will be using a free remotely hosted poll service. That part is easy. But I want to remove the two individual <a href> links that...
4
by: Mario | last post by:
Hello everybody, Does anybody know how i make a script to make a poll? I mean a small poll when you can choose yes or no? -- -------"""------- ---()--- °?----(_)-----?° | Greetz Mario|
0
by: Marcin Szarek | last post by:
Hi! For a few months we suffer mysterious problem with Oracle 10g RAC (more details on server configuration at the bottom). At regular basis (every 5 minutes) nodes of our cluster "freeze" -...
0
by: jinfeng_Wang | last post by:
I have writen the following souce code : m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_Socket.Blocking = false; try {...
1
by: chsalvia | last post by:
I'm try to use poll() to handle network connections on Linux. As a test, I create a simple loop that polls a socket so that everytime the client sends data, the server responds. My problem is...
5
by: pbd22 | last post by:
Hi. I am trying to poll a long-running process via a hidden IFrame. I am noticing that the online errata gives advice for handling a server response: window.parent.handleServerResponse(); ...
0
by: Sophie000 | last post by:
I have some questions about select() and poll(). I heard the poll( ... ) call is usually preferred over and more efficient than select( ... ) simply because poll( ... ) only requires that you...
19
by: geese786 | last post by:
my vote for navia.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.