1
Eunydd
Protector Module - Error : TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool
  • 2/8 20:21

  • Eunydd

  • Just popping in

  • Posts: 6

  • Since: 2022/10/8


I have a clean install of Turnkey Linux XOOPS 18.0 appliance running in VirtualBox 7.1.6 (no Guest Additions). This installs without error and initially XOOPS runs without error : the only modules present are System, Private Messaging, User Profile and Protector. However when I amend Protector Preferences there is a fatal error (even when nothing is actually amended but Go is pressed) :

Error : TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given

The same is true after applying Updates to all four modules, which are error-free in themselves.

My debugging skills have reached there limit and I could do with some support. Any ideas?
Thanks.

XOOPS 2.5.11 Stable
Protector 3.6.2_Stable
PHP 8.2.26
MySql 10.11.6-MariaDB-0+deb12u1
Apache 2.4.6.2

2
Mamba
Re: Protector Module - Error : TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool

I installed XOOPS 2.5.11 on PHP 8.2.27 and also on PHP 8.4, and couldn't replicate the error.

This error happens normally when you want to open a file using
fopen()
do something, and then want to write the results to the file using
fwrite()


When the file couldn't be open in the first place, then fopen() will be false, and you will get your error when you try to write to that file

So you would need to place a check for false before you fwrite()

In code like this:

$fp = @fopen($protector->get_filepath4group1ips(), 'w');
        if (
$fp) {
            @
flock($fpLOCK_EX);
            
fwrite($fpserialize(array_unique($group1_ips)) . "n");
            @
flock($fpLOCK_UN);
            
fclose($fp);
        } else {
            
$error_msg .= _AM_MSG_GROUP1IPSCANTOPEN;
        }


you could check for false:

$fp = @fopen($protector->get_filepath4group1ips(), 'w');
if (
false !== $fp) {


or you could check for false and use Exception:

$fp = @fopen($protector->get_filepath4group1ips(), 'w');
if (
$fp === false) {
    throw new 
FileOpenException("Failed to open file for writing: $filePath (mode: 'w')");
}


Try one by one for the all the fwrite() cases within /xoops_lib/modules/publisher, and see if that helps to identify the issue.

Let us know if that helped to identify the issue.

Also, if I remember correctly, somebody said that there were some problems with an installation provided by the ISP, so you might download the full XOOPS 2.5.11 and reinstall it.

If this is a testing site, you might also download the Beta of XOOPS 2.5.12 and see if the problem is still there.
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

3
Eunydd
Re: Protector Module - Error : TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool
  • 2/9 16:53

  • Eunydd

  • Just popping in

  • Posts: 6

  • Since: 2022/10/8


Thanks, this hinted at a Permissions problem and once I had mastered PHP Error Logging the fix was straightforward.

The PHP Error :
Warning: fopen(/var/local/lib/xoops/data/protector/configcachea07794): Failed to open stream: Permission denied in file /var/local/lib/xoops/lib/modules/protector/class/protector.php line 184
Error: TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool given in file /var/local/lib/xoops/lib/modules/protector/class/protector.php line 185

Fix:
Change directory/file Ownership to root:www-data and Permissions to 0775/0664

4
Mamba
Re: Protector Module - Error : TypeError: fwrite(): Argument #1 ($stream) must be of type resource, bool

Great to hear that you've fixed that!

Thanks for letting us know!
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

Login

Who's Online

168 user(s) are online (131 user(s) are browsing Support Forums)


Members: 0


Guests: 168


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Feb 28
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits