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

fwrite(): Write of 2 bytes failed with errno=22 #45

Open
forenkema opened this issue Dec 7, 2024 · 0 comments
Open

fwrite(): Write of 2 bytes failed with errno=22 #45

forenkema opened this issue Dec 7, 2024 · 0 comments

Comments

@forenkema
Copy link

I have a PHP application which uses piphp. This worked fine on a Raspberry 4. However, after migrating to Raspberry 5, I get the exception: fwrite(): Write of 2 bytes failed with errno=22:

1. in /var/www/basic/vendor/piphp/gpio/src/FileSystem/FileSystem.phpat line 55
46474849505152535455565758596061626364        
$this->exceptionIfFalse($bytesWritten, $extra);
 
        return $bytesWritten;
    }
 
    private function exceptionIfFalse($result, $extra = '')
    {
        if (false === $result) {
            $errorDetails = error_get_last();
            throw new RuntimeException($errorDetails['message'].' '.$extra);
        }
    }
 
    /**
     * {@inheritdoc}
     */
    public function exists($path)
    {
        return file_exists($path);
2. in /var/www/basic/vendor/piphp/gpio/src/FileSystem/FileSystem.php at line 46– PiPHP\GPIO\FileSystem\FileSystem::exceptionIfFalse()
40414243444546474849505152    
{
        $stream = $this->open($path, 'w');
 
        $bytesWritten = @fwrite($stream, $buffer);
        fclose($stream);
        $extra = $path.' '.$buffer;
        $this->exceptionIfFalse($bytesWritten, $extra);
 
        return $bytesWritten;
    }
 
    private function exceptionIfFalse($result, $extra = '')
    {
3. in /var/www/basic/vendor/piphp/gpio/src/Pin/Pin.php at line 166– PiPHP\GPIO\FileSystem\FileSystem::putContents()
160161162163164165166167168     
     *
     * @param string $file The file to write to
     */
    private function writePinNumberToFile($file)
    {
        //echo "file is $file";
        $this->fileSystem->putContents($file, $this->getNumber());
    }
}
4. in /var/www/basic/vendor/piphp/gpio/src/Pin/Pin.php at line 62– PiPHP\GPIO\Pin\Pin::writePinNumberToFile()
56575859606162636465666768     */
    public function export()
    {
        if (!$this->isExported()) {
            $this->exported = true;
 
            $this->writePinNumberToFile($this->getFile(self::GPIO_FILE_EXPORT));
 
            // After export, we need to wait some time for kernel to report changes.
            usleep(200 * 1000);
        }
    }

Debugging shows that the $file = /sys/class/gpio/export and the $buffer = 16. Both seem totally fine to me....

My user (www-data) is in the gpio group (and in the root group). So I believe that file-permissions are not the issue.

Looking around on the internet, it appears that fwrite() errno 22 is caused by writing too much data to a file. That does not seem applicable here, as /sys/class/gpio/export seems to be an emulated file (Is that right? I am not sure).

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

1 participant