php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79507 Ability to determin if socket pers. connection is "new" or already estabilished
Submitted: 2020-04-22 07:13 UTC Modified: 2020-04-22 09:23 UTC
From: slawek1211 at gmail dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: Irrelevant OS: Every operating systems
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 + 37 = ?
Subscribe to this entry?

 
 [2020-04-22 07:13 UTC] slawek1211 at gmail dot com
Description:
------------
For client-server connections using persistent sockets it's sometimes a desirable functionality to send some initialization data when the connection is initially opened. Fore example to submit feature set supported by client (like compression algorithms supported or client version).

As these persistent sockets are managed by PHP it'd be nice to have some function which could be used to assign user data to given socket. This user data would reset when php backend calls connect C function. Or at least some function which would report bytes received and send on $s.

This way user can detect if he got new or already estabilished connection in $s.

Test script:
---------------
$errno = $errstr = 0;
$opt_connect_timeout = 5;
$s = pfsockopen('127.0.0.1', '80', $errno, $errstr, $opt_connect_timeout);


Expected result:
----------------
Being able to write something like this

$errno = $errstr = 0;
$opt_connect_timeout = 5;
$s = pfsockopen('127.0.0.1', '80', $errno, $errstr, $opt_connect_timeout);
if (get_socket_user_data($s) != 'i')
{
 ... send connection initialization data to server ...
 set_socket_user_data($s, 'i');
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-22 07:15 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2020-04-22 07:15 UTC] requinix@php.net
One of the comments on the pfsockopen() page suggests using ftell() to determine whether the connection is new. Does that do what you need?
 [2020-04-22 09:21 UTC] slawek1211 at gmail dot com
-Status: Feedback +Status: Open
 [2020-04-22 09:21 UTC] slawek1211 at gmail dot com
Yes, that's it, so no addition is needed. Thanks
 [2020-04-22 09:23 UTC] slawek1211 at gmail dot com
-Status: Open +Status: Closed
 [2020-04-22 09:23 UTC] slawek1211 at gmail dot com
Closing as ftell can be used to do same thing
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 10:01:30 2024 UTC