FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Sending arbitrary data to/from PHP





bladesage
Okay, well, I have several little things that have been bugging the crap out of me...

These things fall under one basic category.

I need to be able to send AND receive data with PHP scripts!

I want to establish a keep-alive connection (hopefully a socket), from which I can send data from one PHP script to another on a different server. I'd like the scripts from the two different servers to keep sending data back and forth with one connection, and as little hassle as possible.

Second, I want to send data from a C++ script on my computer to a server with another keep-alive connection. So I'd like it to be able to transmit data back and forth from an online PHP script and a home computer, with the same convenient connection system.

I am fairly well-experienced in PHP, and I am getting the hang of C++ pretty quickly, but this is irritating. I need this info ASAP!
Mgccl
I'm not experienced with socket, but I know there is a way we call COMET.

To receive:
Get a PHP page to open a remote HTML page... set the time limit to unlimited...

To send:
set the time limit to unlimited... and just send the information...
read file, a little part at a time, and send them out, so keep the memory low...
if you want to keep CPU low, send something, sleep() for a second, then send things again...

That's the only think I could think of, but you could go around and search for stuff related to this...
bladesage
Well, that much I already can do. The thing is, I want a connection to stay alive. Not reading and sending files back and forth. I mean a real connection, between two scripts.

I am getting fairly good at socket programming, and I learned all about how a request works. So the thing is, although I can connect to a port on a certain server, and listen to that port with a script, how do I tell the remote server that I want to keep a socket alive with a particular script?

I can send data easily enough like so:
Code:
<?php

$sock                     = fsockopen("www.server2.net", 80);

$data                     =
"POST /myscript.php HTTP/1.1\r\n" .
"Content-Type: text/plain\r\n" .
"Host: www.server2.net\r\n\r\n";

fwrite($sock, $data);

$post                     =
"This data will go to the script.";

fwrite($sock, $post . "\r\n\r\n");
fclose($sock);

?>


And receiving data would be reading the returned data. But I want a connection to stay active, with each page waiting for the next response, and acting upon it. THAT is what I need.
Mgccl
let the connection on unless it's deactivated...
like a daemon of something.
http://www.phpclasses.org/browse/package/2197.html
see if it help
Stubru Freak
You don't have to load your PHP pages using a web server. A web server is intended to serve a website, not to keep open connections.
Take a look at http://be.php.net/manual/en/ref.sockets.php . You can invoke a script by typing this on the command line:
php /path/to/script
And it's not necessary to use PHP for this, C++ would also work, or you could use PHP on your home computer, it isn't hard to install (without the web server).
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.