sergix44 / gradio-client-php

Gradio API client for PHP
MIT License
14 stars 2 forks source link

[Bug]: PHP Parse error: syntax error, unexpected 'Config' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/iam/public_html/SergiX44/Gradio/Client.php on line 30 #7

Closed AngelTs closed 12 months ago

AngelTs commented 12 months ago

What happened?

PHP Parse error: syntax error, unexpected 'Config' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/iam/public_html/SergiX44/Gradio/Client.php on line 30

How to reproduce the bug

In "/home/iam/public_html/SergiX44/Gradio/" there are Client, DTO, Event, Exception, Websocket and Client.php In index.php:

<?php use SergiX44\Gradio\Client; ... function testapi() { $client = new Client('https://e8da98b4ef3bbb3c9a.gradio.live/'); $result = $client->predict(['arg', 1, 2]); return $result; } echo testapi(); ?>

Package Version

2.0.0

PHP Version

8.2.0

Which operating systems does with happen with?

Linux

Notes

No response

AngelTs commented 12 months ago

Another error: PHP Parse error: syntax error, unexpected ':', expecting ')' in /home/iam/public_html/php.php on line 57: (line 56) $client = new Client('https://e8da98b4ef3bbb3c9a.gradio.live/'); (line 57) $result = $client->predict(['arg', 1, 2], apiName: 'txt2img');

AngelTs commented 12 months ago

When try to use "file_get_contents()" got the error:

"PHP Warning: file_get_contents(https://d6762460b2254f01cb.gradio.live/): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed in /home/iam/public_html/php.php on line 93"

<?php

$message = $_POST['message'];

$options = [

        'http' => [

            'method' => 'POST',

            'timeout' => 30,

            'header' => [

                'Content-Type: application/json'

            ],

            'content' => json_encode([

                "data" => [

                    [

                        $message

                    ]

                ]

            ])

        ]

    ];

    //Example format of gradio server:

    //$content = '{"data": ["beautiful sky and sunset"],"event_data": null,"event_id": null,"fn_index": 0,"trigger_id": 
0,"session_hash": 0';

    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
</?>
sergix44 commented 12 months ago

What happened?

PHP Parse error: syntax error, unexpected 'Config' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/iam/public_html/SergiX44/Gradio/Client.php on line 30

How to reproduce the bug

In "/home/iam/public_html/SergiX44/Gradio/" there are Client, DTO, Event, Exception, Websocket and Client.php In index.php:

predict(['arg', 1, 2]); return $result; } echo testapi(); ?>

Package Version

2.0.0

PHP Version

8.2.0

Which operating systems does with happen with?

Linux

Notes

No response

Another error: PHP Parse error: syntax error, unexpected ':', expecting ')' in /home/iam/public_html/php.php on line 57: (line 56) $client = new Client('https://e8da98b4ef3bbb3c9a.gradio.live/'); (line 57) $result = $client->predict(['arg', 1, 2], apiName: 'txt2img');

Especially looking at the second one, I dont think you are running php 8.2, if you see those are errors of the interpreter that is not recognizing the named arguments. as valid php syntax.

When try to use "file_get_contents()" got the error:

"PHP Warning: file_get_contents(https://d6762460b2254f01cb.gradio.live/): failed to open stream: HTTP request failed! HTTP/1.1 405 Method Not Allowed in /home/iam/public_html/php.php on line 93"

<?php

$message = $_POST['message'];

$options = [

      'http' => [

          'method' => 'POST',

          'timeout' => 30,

          'header' => [

              'Content-Type: application/json'

          ],

          'content' => json_encode([

              "data" => [

                  [

                      $message

                  ]

              ]

          ])

      ]

  ];

  //Example format of gradio server:

  //$content = '{"data": ["beautiful sky and sunset"],"event_data": null,"event_id": null,"fn_index": 0,"trigger_id": 
0,"session_hash": 0';

  $context = stream_context_create($options);
  $result = file_get_contents($url, false, $context);
</?>

You are trying to communicate with a gradio instance with the API disabled

AngelTs commented 12 months ago

I tried to use file_get_contents without the API, because i can't install it with composer (i am using shared linux hosting, not root access, not ssh), but without success! My PHP on the shared host is PHP 8.1.16

sergix44 commented 12 months ago

I'm sorry but you need both composer and php 8.2 to use this library. Your snippet with file get contents doesnt work because they have disabled the API side of their Gradio server, so even is not possible to use any client with that server.

AngelTs commented 12 months ago

If i understand correctly, i can't use direct neigher curl_exec() nor file_get_contents()? Why they (gradio) did that? Thank you for your time and support