PHP: How to use socket_select() and socket_read() correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PHP: How to use socket_select() and socket_read() correctly
# 1  
Old 08-26-2013
PHP: How to use socket_select() and socket_read() correctly

I have a multithreaded PHP application that uses sockets for communicating between threads. The communication works pretty well, except for one thing: when I call socket_select(), it works the first time after a new connection is made, but after that it always reports read handles ready, even after I've read all the data from them. Here's what I mean:

Main thread:
1. Setup socket, bind to port, listen
2. socket_select() (block, with null timeout to make it wait forever) on the socket from step 1
3. That call works fine: after the child thread connects, socket_select() tells me that the socket from step 1 is ready
4. Accept new connection, remember the handle returned by accept().
5. socket_select() on the main socket plus the new socket
6. After child thread writes, socket_select() reports that the new socket is ready
7. I read all the data from the socket, then go back to step 5.

At this point, socket_select() continues to report that the new socket is ready, even though the child thread has written no new data to it. What in the world am I doing wrong? Is it convention to close the new connection at this point and have the child thread reconnect? How can I get socket_select() to stop reporting that the new handle is ready to read?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Getopts not echoing correctly

Hi, When I run the the following code: #!/bin/bash if ]; then usage fi if ] then echo "Do not execute this as root, use -s instead" fi SERVERFILE="servers" function usage { echo "USAGE: ${0} COMMAND" (4 Replies)
Discussion started by: mohca2020
4 Replies

2. UNIX for Beginners Questions & Answers

Help with function - is placed in script correctly?

Hi Folks - I hope everyone is well. I just need some assistance with a script I've put together. I haven't used functions before so I was wondering if my script is built properly in terms of architecture? The first command of the script shuts down services. Then, the second part finds a... (1 Reply)
Discussion started by: SIMMS7400
1 Replies

3. Shell Programming and Scripting

Subroutines; am I capturing them correctly?

HI Folks - Again, I'm very sorry for the amateur post. I'm reletively new to shell scripting so please bear with me. I have a script that execute another script which stops a particular set of services for my application. IF the execution is successful, I want to check for any hung ESSSVR... (4 Replies)
Discussion started by: SIMMS7400
4 Replies

4. Shell Programming and Scripting

Printf ... some suggestions on using correctly?

Hi all. Probably a silly question... :-( This is my script. $ cat ./QuoteGrabber.sh #!/usr/bin/bash a=$(./DDECmd.exe request -s TOS -t ASK -i /ESM1) b=$(./DDECmd.exe request -s TOS -t BID -i /ESM1) c=$(./DDECmd.exe request -s TOS -t VOLUME -i /ESM1) d=$(./DDECmd.exe request -s TOS -t... (4 Replies)
Discussion started by: paolfili
4 Replies

5. Shell Programming and Scripting

rsync is not correctly working

We are using Red Hat linux system. I am transferring my rman backup files to another server. Here is the command i am using to transfer the files. /usr/bin/rsync -avpP --delete /xyz/xyz/ 99.99.999.99::db110bkp Here is the rsync version. >rsync --version rsync version 3.0.6 ... (1 Reply)
Discussion started by: govindts
1 Replies

6. Shell Programming and Scripting

Escaping ** correctly

Hello This should be easy, but bash is giving me headaches. At the command line the following command works: duplicity --include /home --exclude '**' / file:///foo Doing that from a script is not straightforward. Note that it is basically a requirement that I place the... (3 Replies)
Discussion started by: brsett
3 Replies

7. Shell Programming and Scripting

Is grep being used correctly?

My goal is to find files contain the "signal 11" string in a specific directory. I need the file details followed by the string. I wrote a script to test out and play with Shell command since it's my first time to write a Shell script. Let me cut the story short... this command line: if ... (2 Replies)
Discussion started by: sai0899
2 Replies

8. Shell Programming and Scripting

if not working correctly

Anyone have an idea why this if statement does not work correctly? "test2.sh" 18 lines, 386 characters #!/usr/bin/sh WARNING=80 CRITICAL=95 check_it() { if ] || ];then echo "YES ] || ]" else echo "NO ] || ]" fi } check_it 80.1 check_it 81.1 (3 Replies)
Discussion started by: 2dumb
3 Replies

9. HP-UX

HP-UX will not boot correctly

i've same failure too, but this command boot pri isl not work/not found Thanks! (1 Reply)
Discussion started by: pantas manik
1 Replies

10. UNIX for Dummies Questions & Answers

HP-UX will not boot correctly

I am an intern at a company with an HP visualize C160 running HP-UX B.10.20. It has stopped booting to the gui and, after some coaxing, will end up at a text-based menu screen but virtually nothing can be run from there. At first the computer ran through it's boot process then stopped at this... (5 Replies)
Discussion started by: intern
5 Replies
Login or Register to Ask a Question
php-config(1)							Scripting Language						     php-config(1)

NAME
php-config - get information about PHP configuration and compile options SYNOPSIS
php-config [options] DESCRIPTION
php-config is a simple shell script for obtaining information about installed PHP configuration. OPTIONS
--prefix Directory prefix where PHP is installed, e.g. /usr/local --includes List of -I options with all include files --ldflags LD Flags which PHP was compiled with --libs Extra libraries which PHP was compiled with --man-dir The directory prefix where the manpages is installed --extension-dir Directory where extensions are searched by default --include-dir Directory prefix where header files are installed by default --php-binary Full path to php CLI or CGI binary --php-sapis Show all SAPI modules available --configure-options Configure options to recreate configuration of current PHP installation --version PHP version --vernum PHP version as integer SEE ALSO php(1) VERSION INFORMATION
This manpage describes php, version 5.4.16. COPYRIGHT
Copyright (C) 1997-2010 The PHP Group This source file is subject to version 3.01 of the PHP license, that is bundled with this package in the file LICENSE, and is available through the world-wide-web at the following url: http://www.php.net/license/3_01.txt If you did not receive a copy of the PHP license and are unable to obtain it through the world-wide-web, please send a note to license@php.net so we can mail you a copy immediately. The PHP Group 2010 php-config(1)