helperHandleRead: unexpected read

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

helperHandleRead: unexpected read

499258179
I just start learn squid, and i find a
2019/11/01 00:06:14 kid1| helperHandleRead: unexpected read from timecheck
#Hlpr8, 3 bytes 'OK
'
2019/11/01 00:06:20 kid1| helperHandleRead: unexpected read from timecheck
#Hlpr6, 3 bytes 'OK
in my cache log, timecheck is my php auth for squid
I have follow questions,
1. what is helperHandleRead: unexpected read
2. how to fix this issue




--
Sent from: http://squid-web-proxy-cache.1019090.n4.nabble.com/Squid-Users-f1019091.html
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: helperHandleRead: unexpected read

Amos Jeffries
Administrator
On 1/11/19 6:23 pm, 499258179 wrote:
> I just start learn squid, and i find a
> 2019/11/01 00:06:14 kid1| helperHandleRead: unexpected read from timecheck
> #Hlpr8, 3 bytes 'OK
> '
> 2019/11/01 00:06:20 kid1| helperHandleRead: unexpected read from timecheck
> #Hlpr6, 3 bytes 'OK
> in my cache log, timecheck is my php auth for squid
> I have follow questions,
> 1. what is helperHandleRead: unexpected read

Your helper is sending a line of data to Squid when there has been no
matching query sent to it.


> 2. how to fix this issue
>

Find out why the helper is not delivering only and exactly ONE line of
output (response/result) to each single line of input (query/lookup).

Probably incorrect number of newlines being printed to stdout.

<https://wiki.squid-cache.org/Features/AddonHelpers#What_language_are_helper_meant_to_be_written_in.3F>


Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: helperHandleRead: unexpected read

499258179
Following is my php script, can u check for me, it is looks like  only one
line stdout
<?php

$STDIN=fopen("php://stdin", "r");
$STDOUT=fopen("php://stdout", "w");

$servername = "localhost";
$username = "test";
$password = "test";
$dbname = "test";
$socket = "/var/lib/mysql/mysql.sock";
$conn = mysqli_connect($servername, $username, $password,
$dbname,0,$socket);

if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
        exit();
}

date_default_timezone_set('US/Eastern');

while (!feof($STDIN)) {
$input = trim(fgets($STDIN));
$data = explode(' ',$input);
$username = rawurldecode($data[0]);

$result = mysqli_query($conn,"SELECT * FROM MyGuests WHERE username =
'$username'");
$row = mysqli_fetch_array($result);
$Time_Now = date("Y-m-d H:i:s");
$Start_Date = $row['reg_date'];
$Expire_Date = date("Y-m-d h:i:s",strtotime("$Start_Date +720 hours"));

if($Start_Date < $Time_Now)
{
        if($Time_Now < $Expire_Date)
        {
                fwrite($STDOUT, "OK\n");
                mysqli_close($conn);
        }
        else
        {
                fwrite($STDOUT, "ERR\n");
                mysqli_close($conn);
        }
}
else
{
fwrite($STDOUT, "ERR\n");
mysqli_close($conn);
}
}

?>



--
Sent from: http://squid-web-proxy-cache.1019090.n4.nabble.com/Squid-Users-f1019091.html
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: helperHandleRead: unexpected read

Amos Jeffries
Administrator
On 1/11/19 7:15 pm, 499258179 wrote:
> Following is my php script, can u check for me, it is looks like  only one
> line stdout

How have you tested it?

Your explicit fwrite calls look okay for the expected outputs. But are
they actually the only things producing output?

With PHP any of the functions you call can produce things that the
engine puts on stdout (eg errors, but also debug info) if any one of the
many background config file(s) says to.


FWIW: Have you considered using the DB session helper bundled with Squid?

Something like the below should do the same as your current helper.
Double check the --cond syntax, it has been a while since I dealt with
MySQL timestamp math.


external_acl_type guests %un /usr/lib/squid/ext_sql_session_acl \
  --dsn DBI:mysql:database=test:localhost:3306 --persist \
  --user test --password test \
  --table MyGuests --uidcol username \
  --cond "NOW() < DATETIME_ADD(reg_date, INTERVAL 720 HOUR)"


Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: helperHandleRead: unexpected read

499258179
I just use php function call my pho script, such as php /etc/test.php.
When I type test1, stdout only have OK



--
Sent from: http://squid-web-proxy-cache.1019090.n4.nabble.com/Squid-Users-f1019091.html
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: helperHandleRead: unexpected read

Amos Jeffries
Administrator
On 2/11/19 11:58 am, 499258179 wrote:
> I just use php function call my pho script, such as php /etc/test.php.
> When I type test1, stdout only have OK
>

No empty lines?

Is your squid.conf set to use concurrency for this helper? (this script
cannot handle that).

Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users