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

fclose() expects parameter 1 to be resource, boolean given #595

Closed
harsh-pawar opened this issue Jun 25, 2018 · 4 comments
Closed

fclose() expects parameter 1 to be resource, boolean given #595

harsh-pawar opened this issue Jun 25, 2018 · 4 comments

Comments

@harsh-pawar
Copy link

harsh-pawar commented Jun 25, 2018

While connection from browser to printer print successfully but after $printer -> close(); it throws fclose() expects parameter 1 to be resource, boolean given error

@mike42
Copy link
Owner

mike42 commented Jun 25, 2018

Hello, I have not seen this myself.

Would you mind sharing a self-contained example which shows the problem? This would allow me to run it myself, and also ses how you are using the library. Ideally you could also add some information about your platform, such as your OS and PHP version.

@harsh-pawar
Copy link
Author

`<?php
require base_path().'/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\Printer;
try {
$connector = new NetworkPrintConnector("192.168.1.123", 9100);
$printer = new Printer($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
//
// /* Close printer */
$printer -> close();

} catch (Exception $e) {
    echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";

} finally {
    ob_clean();
    flush();
    $printer->close();
}
?>`

I have just use above code
My Platform is : Laravel 5.6
I am using Xampp server on Ubuntu 18.04 and php version is : 7.2.4

@mike42
Copy link
Owner

mike42 commented Jun 26, 2018

Excellent.

So, you are closing the printer twice. Remove the first call to $printer -> close() then this issue will go away.

It is a bug that escpos-php throws a warning here, I would expect it to silently ignore the second close().

@JonesSmithNew
Copy link

Thank you mike42, you are great!

You have just saved my ass!

I had a problem of opencart upgrade php problem that shows "Warning: fclose() expects parameter 1 to be resource, boolean given in /var....../log.php on line 14 Warning: fclose() expects parameter 1 to be resource, boolean given in...."!!

After your answer, I though there is ,also, double closed problem! So I comment out the line 14 on the log.php. So, now the problem has gone. My website working like a charm!

Thank you mike42! Good man!!

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

3 participants