Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

socket_write(3) [php man page]

SOCKET_WRITE(3) 							 1							   SOCKET_WRITE(3)

socket_write - Write to a socket

SYNOPSIS
int socket_write (resource $socket, string $buffer, [int $length]) DESCRIPTION
The function socket_write(3) writes to the $socket from the given $buffer. PARAMETERS
o $socket - o $buffer - The buffer to be written. o $length - The optional parameter $length can specify an alternate length of bytes written to the socket. If this length is greater than the buffer length, it is silently truncated to the length of the buffer. RETURN VALUES
Returns the number of bytes successfully written to the socket or FALSE on failure. The error code can be retrieved with socket_last_error(3). This code may be passed to socket_strerror(3) to get a textual explanation of the error. Note It is perfectly valid for socket_write(3) to return zero which means no bytes have been written. Be sure to use the === operator to check for FALSE in case of an error. NOTES
Note socket_write(3) does not necessarily write all bytes from the given buffer. It's valid that, depending on the network buffers etc., only a certain amount of data, even one byte, is written though your buffer is greater. You have to watch out so you don't uninten- tionally forget to transmit the rest of your data. SEE ALSO
socket_accept(3), socket_bind(3), socket_connect(3), socket_listen(3), socket_read(3), socket_strerror(3). PHP Documentation Group SOCKET_WRITE(3)

Check Out this Related Man Page

SOCKET_SET_OPTION(3)							 1						      SOCKET_SET_OPTION(3)

socket_set_option - Sets socket options for the socket

SYNOPSIS
bool socket_set_option (resource $socket, int $level, int $optname, mixed $optval) DESCRIPTION
The socket_set_option(3) function sets the option specified by the $optname parameter, at the specified protocol $level, to the value pointed to by the $optval parameter for the $socket. PARAMETERS
o $socket - A valid socket resource created with socket_create(3) or socket_accept(3). o $level - The $level parameter specifies the protocol level at which the option resides. For example, to retrieve options at the socket level, a $level parameter of SOL_SOCKET would be used. Other levels, such as TCP, can be used by specifying the protocol number of that level. Protocol numbers can be found by using the getprotobyname(3) function. o $optname - The available socket options are the same as those for the socket_get_option(3) function. o $optval - The option value. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 socket_set_option(3) example <?php $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); if (!is_resource($socket)) { echo 'Unable to create socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1)) { echo 'Unable to set option on socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } if (!socket_bind($socket, '127.0.0.1', 1223)) { echo 'Unable to bind socket: '. socket_strerror(socket_last_error()) . PHP_EOL; } $rval = socket_get_option($socket, SOL_SOCKET, SO_REUSEADDR); if ($rval === false) { echo 'Unable to get socket option: '. socket_strerror(socket_last_error()) . PHP_EOL; } else if ($rval !== 0) { echo 'SO_REUSEADDR is set on socket !' . PHP_EOL; } ?> PHP Documentation Group SOCKET_SET_OPTION(3)
Man Page

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

length of data greater than 11

I need to get all the rows in a file, for which length of field at column 6 is greater than 11. I tried awk '{ if ($#1 >11) print $1}' filename But Iam getting some errors I tried different combinations like awk '{ if (${#$1} >11) print $1}' filename awk '{ if (${#1} >11) print... (2 Replies)
Discussion started by: thanuman
2 Replies

2. Programming

how to clear/clean mbufs (network buffer space)?

When I worked with client-server (socket) programming, I encountered "the socket error# 10055" which means "No buffer space available". This might be a symptom of one or more applications that didn't return system resources (like memory) properly. Temporary solution was to reboot the machine to... (7 Replies)
Discussion started by: dipti
7 Replies

3. Programming

Client - server program

i came acors this coding when surfin the net.this code works perfectly.but as i am new to this socket programming i need sm coments quoted on it or explanation regarding this source code. i have prb understanding the server.c i have posted it below can u guys help me !!!! cheerZ The... (4 Replies)
Discussion started by: mathu
4 Replies

4. Shell Programming and Scripting

Counting the max length of string

Hi all, I have a flat file of 1000 rows. I want to check the length of the 5th column. The one having the longest length , I want to set it as DEFINED PARAMETER. So later I can check others with that particular number only. Any ideas ?? (2 Replies)
Discussion started by: ganesh123
2 Replies

5. Programming

Strange character added when reading to buffer with length of 12

Hi all, I got trouble with reading and writing ( to standard input/output, file, socket whatever...). I will briefly describe it by giving this example. I want to read a long string from keyboard but i don't know how long it is b4. So i need to know the number of character i will read first.... (6 Replies)
Discussion started by: tazan_007
6 Replies

6. UNIX for Dummies Questions & Answers

check length content existence of variable

hi guys, im learning so be gentle... i'm wanting to write a script to read in a customer number. in order that the code is robust i want to check 1) the length of the value entered (4 characters) 2) that all characters entered are numeric between the values 1 to 3 3) that a value is... (1 Reply)
Discussion started by: skinnygav
1 Replies

7. Programming

Write-Write on a socket

Can anyone tell what happens if each end writes at the same time on the same socket ? - if one of them issues a read() after write() has completed, will it record into the buffer what the other sent ? ex. e1 writes to e2 - - - while - - - e2 writes to e1 (at the same time) e1 read () - what... (1 Reply)
Discussion started by: gendaox
1 Replies

8. Shell Programming and Scripting

Length validation

I am using below code to find the length of first column additionally I want the complete row which length is greater than 12.at the end I want the rows where first column data length is greater than 12. Just it should validate and highlight the rows where length(first column) is greater than... (5 Replies)
Discussion started by: srivalli
5 Replies

9. Programming

Hash Table

I was looking at this script and was wondering if anyone can explain what this script does and how does it work. Thank you for any help. State* lookup(char* prefix, int create) { int i, h; State *sp = NULL ; h = hash(prefix); for (sp = statetab; sp != NULL; sp... (14 Replies)
Discussion started by: totoro125
14 Replies