I have a server.php:

<?php
set_time_limit (0);

$host = '127.0.0.1';
$port = 1234;

$sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("could not create socket");

socket_bind($sock, $host, $port) or die("Could not bind to socket\n");

socket_listen($sock, 3) or die("Could not set up socket listener\n");

while (true) 
      {
      $spawn = socket_accept($sock) or die("Could not accept incoming connection\n");
      $input = socket_recv($spawn, $c, 1024, MSG_WAITALL) or die("Could not read input\n");

  socket_write($spawn, $input, strlen ($input)) or die("Could not write output\n");

  }
?>

and a client.php has the following relevant code:

$localhost = "127.0.0.1";
$localport = 1234;
$msg = "hi";

			$fp2 = socket_create(AF_INET, SOCK_STREAM, 0);
			socket_connect($fp2, $localhost, $localport) or die("connect failed");
			socket_send($fp2, $msg, 1024,0) or die("send failed");

I'm trying to get the server to receive the message "hi". Any help would be appreciated. Thanks in advanced.

    Or does anyone have any other suggestions. Heres what i want to do.

    Client.php does some work, once it finishes doing it, it'll send a flag to server.php telling it its been done.

    I'm a java programmer and know theres things like instantiating an object of that class, but don't know any other way other than sockets for php.

      why not just call (include() or require()) server.php when client.php is done?

        I agree with dagon. There is (most likely) a better way of doing this.

        But if you do want something to run indefinitely, you should make it run in the background. Do it yourself, or perhaps try a web search for create php daemon. Also, do use sleep() so you don't hog all available resources.

        Other than that, what's not working with your code? Any errors?

          Theres no errors, it just doesn't work. Which is odd.
          But yeah I want the two programming running concurrently.

          When the client finishes working, it sends something to the Server for it to work. But the client will stay up and send more stuff to the Server.

          Sorry that I didn't specify this. You guys think a daemon will be better for this situation?

            Actually, the Server and client do connect to each other. The message doesn't get sent and printed off in the Server though.

              You never check if it's sent/received, so how do know? And you never echo anything, so there should be no output. $input will be false on error, or number of bytes sent.

              if ($bytes_sent = socket_send() !== false)
              if ($bytes_received = socket_recv() !== false)
              
                Write a Reply...