Bug #80803 [Opn->Fbk]: socket_read() reference to global socket fails in user function
| From: | requinix@php.net | Date: | Fri, 26 Feb 2021 16:44:29 +0000 |
| Subject: | Bug #80803 [Opn->Fbk]: socket_read() reference to global socket fails in user function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232401@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80803&edit=1
ID: 80803
Updated by: requinix@php.net
Reported by: janui at onmat dot com
Summary: socket_read() reference to global socket fails in
user function
-Status: Open
+Status: Feedback
Type: Bug
Package: *Data Exchange functions
Operating System: Linux 5.10.14-2-ARCH armv7l
PHP Version: 8.0.2
Block user comment: N
Private report: N
New Comment:
> The text and script provided should be enough to explain the problem.
Explain, yes. Reproduce, no.
My own implementation (which ran correctly) was about 40 lines or so. That's not too much to
put here. If yours is much longer than that, create a gist or put it on Pastebin or wherever.
Previous Comments:
------------------------------------------------------------------------
[2021-02-26 16:09:55] janui at onmat dot com
The text and script provided should be enough to explain the problem. I can provide you with a full
example, but this will be far in excess of the 20 lines of code limit which you specify as a limit.
You will also need to have a server process which will initiate a socket and reply to the test
requests. Any socket server process will suffice. My current solution is fully tested and works with
PHP7.4.13-1 (syntactically & run-time correct). As I already specified, the problem relates only
to socket_read(), the other PHP8 socket functions work without problems. And the identical code for
the socket_read() problem works correctly when executed directly in the calling script (also
syntactically & run-time correct). Please specify which server proces you wish to use for
testing/debugging and advise on the 20 lines limit.
------------------------------------------------------------------------
[2021-02-26 15:39:36] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.
A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.
Please avoid embedding huge scripts into the report.
------------------------------------------------------------------------
[2021-02-26 11:02:37] janui at onmat dot com
Description:
------------
---
From manual page: https://php.net/function.socket-read
---
When a user function contains a socket_read() which references a globally defined socket object it
fails to connect to and read the socket. When the same code used in the top-level script it works
correctly. The problem is not present in the socket_connect(), socket_write() and socket_close()
functions.
function user_function_read_socket($socketVariableName)
{
$buff = 4096;
global $$socketVariableName;
echo $socketVariableName."\n";
var_dump($$socketVariableName);
$response = socket_read($$socketVariableName, $buff, PHP_NORMAL_READ);
echo $response."\n";
echo socket_strerror(socket_last_error($$socketVariableName))."\n";
}
The following similar construction has no effect on the result:
$response = socket_read($GLOBALS[$socketVariableName], $buff, PHP_NORMAL_READ);
Test script:
---------------
See description. A full test script can be delivered., something like this:
<?php
function user_function_open_socket($socketVariableName)
{...}
function user_function_write_socket($socketVariableName, $command)
{...}
function user_function_read_socket($socketVariableName)
{...see description...}
function user_function_close_socket($socketVariableName)
{...}
$socketVariableName = 'testSocketName';
$command = 'a valid command';
user_function_open_socket($socketVariableName);
user_function_write_socket($socketVariableName, $command);
user_function_read_socket($socketVariableName);
// paste the code from the read function here
user_function_close_socket($socketVariableName);
Expected result:
----------------
I would expect the code to work in the same way regardless of being used in the top level script as
in a user function.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80803&edit=1