Can a web (php) server send data without request?
Miscellaneous Forums/General Discussion/Can a web (php) server send data without request?
Does anyone know if there is a way to make the type of server used for standard websites to send data to a known IP address?
I want a client to visit a php page (using client software not browser), and then (in any way possible) have the client not connect to the server again, but instead have the server send data to client's listening port after some time.
Say it is one expensive deticated server with most of things installed (JAVA, PHP, ASP, etc). Or in the other case, what would be minimum requirements?
Maybe I could simply put a delay in the php script but then it would have to keep checking if the variable needed has changed and to send it to the client, which i dont want to do, so i need an "active" way of sending data.
Any help please?
Does anyone know if there is a way to make the type of server used for standard websites to send data to a known IP address?
Not really.
Say it is one expensive deticated server with most of things installed (JAVA, PHP, ASP, etc). Or in the other case, what would be minimum requirements?
Well from what I can tell from your post above the best option in your case would be to write your own server. The requirements would then be a Linux/BSD server with a shell account and inetd. Since inetd works using stdin and stdout, it should work with a BlitzMAX linux application, and you should be able to communicate back and forth using "Print" and "Input" statements.
In a couple of months, I'll be attempting something similar to this, so let me know how far you get.
Maybe I could simply put a delay in the php script
You could. But the TCP stack would probably time out the request eventually.
A BlitzMax server? Well i must say that is one idea i didnt dare think about just yet. But a good idea it is.
Do you think such a dedicated programmed server of average quality would cost more to rent than an average php server?
It's just that i would need a lot of testing, i thought to rent a cheap php server for that, and later on php servers are cheaper in general.
Do you think such a dedicated programmed server of average quality would cost more to rent than an average php server?
Definately. But only because an average php server is dirt cheap, and you have to share it with others. In Denmark a decent dedicated server with a proper service plan will set you back about 50-75 USD a month. You can get it cheaper if you want (you could even do it yourself if you really wanted too) but it's probably not worth the extra work.
50-75 ONLY??? Wow, i guess i have to spend much more than 2 hours googling. I didn't find any as cheap as that yet. I suppose that includes remote admin, and it wouldnt matter that much that im in another part of the World? If you could recommend any, that will be sweet. I'm still doing cost estimates, and i dont think i'll be using them until mid 2006.
How do you mean i could do it by myself? I'm not lazy to put in some work you know. I was thinking, buy my own machine and get some friend with a good connection to host it, what were you thinking?
I suppose that includes remote admin, and it wouldnt matter that much that im in another part of the World?
Nope. Ours is in Germany IIRC. I'll try and see if I can get a name for you on Monday.
I'm not lazy to put in some work you know.
It's not about being lazy it's about it genuinely not being worth it cost/benefit wise.
I was thinking, buy my own machine and get some friend with a good connection to host it, what were you thinking?
Yeah, that's pretty much it. Or get the good line for yourself. I'd recomend one of those completely silent, and very small ITX systems (like a Lexcom or something) if you're going to hook it up at someone elses place tho'.
Might not be what you want, but...
Could you have your first php page serve up some HTML that had a refresh command in the header. This would let you specify another page to retrieve after a certain amount of time. You might want to work with the 'Blitz in a browser' stuff that Mr Picklesworth has been putting together... could give you a workaround for what you are trying to achieve.
... just a thought !
or used a cron-job instead and open a tcp connection from within this php-script to connect to your local client. most webhosters have an option for additional cron-jobs starting for 50cent/month or something...
@Black, well i can achieve the page being refreshed every 10 seconds in a simpler way but that's a bandwidth overhead i dont like so much. However, i believe that i will do my testing using this method and get a full linux server later with active client/server communication.
@Ojay, i googleed "cron-job" but i dont think it can be made to send data to a user without previous query. I need the server to send the data after an event, and not have the user constantly check if the event occured but have the server tell him (initiate a connection).
Theres another idea i could do it through IRC :P
just a note.... I hate when a website takes control away from me. Pop ups, Pop unders, thats shades, and when it decides that it wants to refreash while I'm reading.
Be very careful that whatever you are doing, it is transparent to the user.
Head over to Deviant Art www.deviantart.com I don't know what you want, but they have a few things that update without the user asking for it... But I don't know if the code the user has is asking or not.... never cared to look or ask... But if you ask them something simple.. I'm sure they will answer...
Um... also www.okcupid.com has even more things that seem to do what you are looking for... If not.. It might be close enough to work how you want... and if you join the site and then e-mail the people who make it, they are pretty good about giving out ANY kind of help... if it isn't a complicated 10 page paper, they'll give you some help too...
Last ditch? try good ol webmonkey www.webmonkey.com i think...
I don't see what's so complicated here. PHP has TCP functions. The only requirement of your host is that you can disable their CGI Timeout: on a typical web server setup, scripts are killed after 90 seconds or so.
Keep in mind that your clients will need to make their port accessible. Some people (like me) have no choice about being behind a restrictive firewall.
A quick google search for PHP+TCP+connect found the fsockopen PHP command. There may be other ways to do this, but this one looks pretty straightforward. The example shows the other relevant commands:
http://www.phpbuilder.com/manual/function.fsockopen.phpIf you let me know what it is exactly that you're trying to do, I may be able to help more.
Dampe: read the original post. The author requires that you're running his custom software - not a browser.
P.S. Regarding the "delay" approach, TCP itself will not kill your connection. A "checkpoint firewall" along the way might, however. The conventional keep-alive strategy is to send an occasional "NOOP" packet which the other party should ignore. This is certainly a valid and clean approach (and probably better than requiring an open port!)
Dampe, i believe they are simply using a timed refresh which is not what i need.
octo,
The "only requirement" is not an easy one :) because i am looking to find a cheap host for the lengthy testing and only better hosts have such options and it will take time to find them. I didn't see this command before, which means i'm not good at using google (what do the + signs stand for and how do they help in a search?).
Since i'm going to be writing the client code, i'll try to leave an option to use the http port only (port 80) like any other browser, but there will also be lots of configuration options to make it work behind a firewall. Thanks for the note.
I decided for testing i will most likely have the clients connect every 10-20 seconds and check for an update (because the game is semi-realtime). Then, for the version 1.0 i will make the server in BlitzMax and put it on a linux box.
More exactly: The game is tick based, and a tick happens every 30 minutes but inbetween ticks people can move their units (for example) as well as do other things. So the server has to check for each player if the unit has been moved so that it sends the data on where the unit should appear on other player's screens. The server can know when data needs to be sent, but the user must be told. So for testing, the user will check every 10 seconds and if there is an update for him he will download the data. Or i will try the less reliable fsockopen command, i mean less reliable because of firewalls and ISP specifications. Then later, as i said, it wont be php but in bmax (also with SQL probably) which will have an open tcp connection.