Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sendFile not working #182

Closed
gsfordham opened this issue Nov 21, 2016 · 21 comments
Closed

sendFile not working #182

gsfordham opened this issue Nov 21, 2016 · 21 comments

Comments

@gsfordham
Copy link

$message->channel->sendFile( __DIR__ . "/media/test.jpg", "test.jpg", "testContent");

So, the file won't let me rename it after running this. Says the file is OPEN with PHP, but the thing is: it doesn't send. When the file doesn't even exist, it sends an empty, 0kb file of name "test.jpg" and echos an error to my prompt, but when the file exists, it does nothing. At all. It doesn't write an error to my prompt, but it also doesn't send the file; it's as if it succeeded in sending it, but it didn't.
And it STILL responds afterward, so it's not hanging. It just opens the file, does nothing with it, and then continues.

Is there a different way I'm supposed to do this?

@ghost
Copy link

ghost commented Nov 21, 2016

I have the same problem

if ($message->content == $config["bot"]["trigger"].'test') { $message->channel->sendFile( __DIR__ . "/asgard.jpg", "asgard.jpg", "testContent"); }

nothing happens and even i get no error message

@gsfordham
Copy link
Author

Still no updates to this?

@davidcole1340
Copy link
Member

davidcole1340 commented Dec 9, 2016

@gsfordham @Darklandz Sorry for late reply, not sure about master but sendFile is working on the develop branch. I'll push a release to master sometime today. Is there another issue that I don't see?

@illu23
Copy link

illu23 commented Dec 13, 2016

got the same problem and no error output .. got in the runRequest from httpdriver but my php coding experience is not that good :/

@haolink
Copy link

haolink commented Jan 8, 2017

I can confirm this isn't working.

I was trying both on version v4.* in composer.json as well as dev-develop. On v4.* the entire php process is crashing, on dev-develop it seems to be trying to send a file but it fails to submit the Promise.

An error occurred in the underlying stream
#0 [internal function]: React\HttpClient\Request->handleError(Object(RuntimeException), Object(React\Stream\Stream))
#1 /srv/dphp/bot/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Array, Array)
#2 /srv/dphp/bot/vendor/react/stream/src/Stream.php(61): Evenement\EventEmitter->emit('error', Array)
#3 [internal function]: React\Stream\Stream->React\Stream\{closure}(Object(RuntimeException), Object(React\Stream\Buffer))
#4 /srv/dphp/bot/vendor/evenement/evenement/src/Evenement/EventEmitterTrait.php(64): call_user_func_array(Object(Closure), Array)
#5 /srv/dphp/bot/vendor/react/stream/src/Buffer.php(110): Evenement\EventEmitter->emit('error', Array)
#6 [internal function]: React\Stream\Buffer->handleWrite(Resource id #245, Object(React\EventLoop\StreamSelectLoop))
#7 /srv/dphp/bot/vendor/react/event-loop/src/StreamSelectLoop.php(240): call_user_func(Array, Resource id #245, Object(React\EventLoop\StreamSelectLoop))
#8 /srv/dphp/bot/vendor/react/event-loop/src/StreamSelectLoop.php(201): React\EventLoop\StreamSelectLoop->waitForStreamActivity(34387433.052063)
#9 /srv/dphp/bot/vendor/team-reflex/discord-php/src/Discord/Discord.php(1231): React\EventLoop\StreamSelectLoop->run()
#10 /srv/dphp/bot/test.php(54): Discord\Discord->run()

The code is kept rather simple because I wasn't sure if my big project was broken. So I literally broke it down to:

$discord = new Discord([
    'token' => $token
]);

$discord->on('ready', function ($discord) {
    echo "Bot is ready!", PHP_EOL;

    // Listen for messages.
    $discord->on('message', function ($message, $discord) {
        $message->channel->sendFile('/srv/dphp/files/img_10F4b1C7ffQrPeo.jpg', 'img.jpg', 'Image', false)
                ->then(
                        function($msg) {
                                echo 'OKAY!';
                                die('Bye bye'); //Making sure it won't reply to itself!
                        })
                ->otherwise(
                        function($e) {
                                echo $e->getMessage() . PHP_EOL;
                                echo $e->getTraceAsString() . PHP_EOL;
                        });
    });
});

$discord->run();

@haolink
Copy link

haolink commented Jan 9, 2017

Okay, I shall reply myself here - this is something interesting.

I was debugging into the error - and well, DiscordPHP is not to blame. This seems to be an error which only occurs on certain PHP configurations. I'm using Ubuntu 16.04 with Ondrej Sury's PHP PPA (see https://launchpad.net/~ondrej/+archive/ubuntu/php ).

Personally I am thus using PHP 7.0.14 to run the bot.

The bug affects the OpenSSL extension of PHP - I can reconstruct it in PHP 5.6, PHP 7.0 and PHP 7.1 - I created a separate PHP CLI client by recompiling Ondrej Sury's PHP CLI interpreter with the bug fix at PHP from https://bugs.php.net/bug.php?id=72333 included (not as /usr/bin/php but as /usr/bin/php_sslbot so that a future package upgrade wouldn't immediately overwrite it).

The bug is also discussed at the ReactPHP GitHub see reactphp/stream#64 - so yeah, so far using this recompiled PHP works - I doubt this is a bug DiscordPHP can fix for affected PHP installations.

@Shadowfied
Copy link

Shadowfied commented Jan 21, 2017

For me, only files under 100 KB work.
My php.ini allows for several MBs (upload_max_filesize, post_max_size etc)..
Any ideas on how I can send any file (as long as it's within Discords limit ofc)?

@BuzzMoody
Copy link

Yeah this still doesn't work, looks like PHP peeps aren't in a rush to fix it.

@cryptiklemur
Copy link
Contributor

@BuzzMoody "@ gsfordham @ darklandz Sorry for late reply, not sure about master but sendFile is working on the develop branch. I'll push a release to master sometime today. Is there another issue that I don't see?"

@BuzzMoody
Copy link

Doesn't work on either branch on both Debian and Ubuntu.

@BuzzMoody
Copy link

@haolink Able to share your recompiled PHP CLI client?

@donkkill13
Copy link
Contributor

I'm pretty sure that replacing fopen() with file_get_contents() will fix the issue, but it won't be as clean and I think file_get_contents() blocks or something

@haolink
Copy link

haolink commented Mar 16, 2017

The issue is finally fixed on the PHP upstream. See http://git.php.net/?p=php-src.git;a=commit;h=17e9fc9bfeaf575b25782a42937a56e809155858

@BuzzMoody - sorry I didn't notice your ping so I didn't react. The thing is: I can share the client but it's basically built from Ondrej Sury's PHP 7.0 builds - so it is linked against Ubuntu 16.04 and PHP 7.0 libraries by him - I tested on Vanilla Ubuntu 16.04 and like expected it didn't run - it ran into many missing libraries. So yeah: if you have such a configuration I can share the binary - if not it will probably be a waste of time - however, the upstream of PHP has it, so if you use quick release cycles you should have it rather soon ^^.

@davidcole1340
Copy link
Member

Closing as this seems to be fixed with PHP. Working for me on develop branch.

@BuzzMoody
Copy link

Still not working on Debian 10, PHP 7.4.10 and dev branch

@Ravisdo
Copy link
Contributor

Ravisdo commented Oct 4, 2020

@BuzzMoody could you retry with the latest master? It got a few changes in the last past days

@BuzzMoody
Copy link

@BuzzMoody could you retry with the latest master? It got a few changes in the last past days

"PHP Warning: array_key_exists() expects parameter 2 to be array, bool given in /home/buzz/DiscordPHP/vendor/team-reflex/discord-php/src/Discord/Http/Http.php on line 145"

@davidcole1340
Copy link
Member

Line 145 on the master branch is an anonymous function line, it's likely you are on an older version. Can you run composer require team-reflex/discord-php dev-master to get the latest.

@davidcole1340 davidcole1340 reopened this Oct 4, 2020
@BuzzMoody
Copy link

Hey David, I updated to dev-master as you suggested. I now no longer get any errors it just won't send the image. No output, but keeps running fine.

davidcole1340 added a commit that referenced this issue Oct 4, 2020
@davidcole1340
Copy link
Member

@BuzzMoody Could you update again please, just with composer update. It's working for me now, seemed to be an oversight when switching to react/http however we only made the switch a couple weeks ago so there could be another issue for you.

@BuzzMoody
Copy link

It's working! You're a genius <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants