LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-06-2005, 12:15 PM   #1
mrobertson
Member
 
Registered: May 2005
Posts: 275

Rep: Reputation: 30
recieving multiple messages with a php server


I have the following php server coded below:

<?php
function giveMeAnArray($delimiter, $string) {
return explode($delimiter, $string);
}

/* Copy this script to the two boxes you want to use. Uncomment the line saying "read" on the
* server box; and uncomment the line saying "write" on the client box.
*/
$read_write = "read";
//$read_write = "write";

//This is the server half
if ($read_write == "read") {
//Initialize the socket
set_time_limit(0);
$address = '127.0.0.1';
$port = 10119;
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_bind($sock, $address, $port) or die ('Could not bind to address');

//Start listening on the socket
While(1)
{//There could be a 'while true' or something here to make it infinite
socket_listen($sock);

//Accept an incoming connection
$client = socket_accept($sock);

//Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
$global_string = socket_read($client, 1024);

print ("Read a string!\n");
//Strip whitespace
$global_string = ereg_replace("[ \t\n\r]", "", $global_string).chr(0);

$delim = ',';

$array = giveMeAnArray($delim, $global_string);

print ("Global string before being parsed: $global_string\n");
print ("Global string after being parsed:");

for($i=0; $i < count($array); $i++)
{
print("Coil ID: $array[0]\n");
print("Coil Width: $array[1]\n");
print("Footage Count: $array[1]\n");
print("Coil Length: $array[3]\n");
}

}//Close the while loop here, if you had one

//Close the connection; and the socket itself. Don't leave things like this open...!!
socket_close($client);
socket_close($sock);

print ("Closed socket successfully\n");
print ("Server exiting now...\n");
} //ends if ("read")

I was under the inpression that the while loop that I have would emable my program to recieve new messages every second but I keep getting a not responding application when run. I have a client that is passing four values to the server which are updated every second. Without the while loop I am able to recieve the first set of valuesbut nothing else. Does anyone know some syntax on how to setup this server to recieve messages that are set on a timer to be sent every second?
 
Old 06-06-2005, 12:56 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
If you run the script with the php interpreter that run as module
with apache, you have to work with apache limits (RLimitCPU)
 
Old 06-06-2005, 01:01 PM   #3
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I am currently running the server with the tulip php interpreter. What do I need to do for this particular interpreter. Also I have the server on knoppix but could never get an interpreter that would not error out. I tried #!/usr/bin/php, #!/usr/local/bin/php and kept getting a bad interpreter error which is why I tried tulip in the first place. Any suggestions for both tulip and knoppix
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recieving Audio From Multiple Programs At The Same Time willigiann SUSE / openSUSE 1 08-17-2005 03:25 AM
Receiving multiple messages with a php Server mrobertson Programming 30 06-13-2005 07:11 AM
php server recieving multiple messages mrobertson Programming 6 06-09-2005 12:55 PM
Multiple instances of PHP cubax Linux - Newbie 6 12-30-2004 08:04 PM
Php Warnings Messages Bheki Linux - General 3 05-20-2002 01:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration