fwrite(): Write of 2 bytes failed with errno=22
Opened this issue · 0 comments
forenkema commented
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).