fclose(): Argument #1 ($stream) must be of type resource, bool given
Asked Answered
R

12

12

I just restart my laravel 8.0 project and I got this below error, please what could be wrong, this happens anytime I run "PHP artisan serve"

   TypeError

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

  at C:\Users\owner\Laravel-App\test-app\vendor\symfony\process\Pipes\WindowsPip
es.php:74
     70▕                         fclose($this->lockHandles[$pipe]);
     71▕                     }
     72▕                     $this->lockHandles[$pipe] = $h;
     73▕
  ➜  74▕                     if (!fclose(fopen($file, 'w')) || !$h = fopen($file
, 'r')) {
     75▕                         flock($this->lockHandles[$pipe], \LOCK_UN);
     76▕                         fclose($this->lockHandles[$pipe]);
     77▕                         unset($this->lockHandles[$pipe]);
     78▕                         continue 2;
       continue 2;

  1   C:\Users\owner\Laravel-App\test-app\vendor\symfony\process\Pipes\WindowsPi
pes.php:74
      fclose()

  2   C:\Users\owner\Laravel-App\test-app\vendor\symfony\process\Process.php:130
4
      Symfony\Component\Process\Pipes\WindowsPipes::__construct()
Reitareiter answered 8/2, 2021 at 21:11 Comment(7)
Not sure about laravel but i dont think you can have the fopen inside of the close like that, don't you need the handle to have its own var? like this: $fopen = fopen($file, 'w'); then use if (!fclose($fopen) || !$h = fopen($file, 'r')) maybe?Fructification
thank you for replying when i uesd $fopen = fopen($file, 'w'); if (!$fopen || !$h = fopen($file, 'r')) it works but giving another error "404 NOT FOUND"Reitareiter
Maybe your $file doesn't exist? And before you had it like this: if (!fclose($fopen) || !$h = fopen($file, 'r')) NOT like this if (!$fopen || !$h = fopen($file, 'r')). Not sure if that could have something todo with it.Fructification
Have you tried restarting your machine?Weathercock
i have treid restarting and gettting those errorReitareiter
Please share more details - how is this related to composer-php or window?Sodomy
i really dont know why this is affecting my whole project on this machine, when ever i run anything it gives that error, even though i run "composer update, it gives this errorReitareiter
F
23

You can open the task manager then look for CLI (with the php logo) background process, if you find it then kill task

Fahrenheit answered 23/2, 2021 at 6:14 Comment(0)
P
6

Don't restart, don't uninstall, don't panic !

If you are on Windows Machine then follow these below step :

  1. Click the Start charm.

  2. Type cmd, right-click the Command Prompt tile, and then click Run as administrator.

  3. Type tasklist /v | find "php" press enter and find the PID of php.exe

  4. Kill the process by taskkill /PID <PID> /F

  5. You are done.

Pyroelectricity answered 6/2, 2022 at 13:25 Comment(0)
S
4

I had another Laravel application running that I forgot about (in the terminal of another IDE). Ctl + C (killing) that allowed me to get past this error msg.

Shanel answered 27/11, 2021 at 1:5 Comment(0)
S
0

I had the same error today and applied all the solutions but this resolved my error.

  1. Un-install the composer.
  2. Restart your machine
  3. Install the composer
Slushy answered 1/5, 2021 at 19:18 Comment(0)
N
0

First run composer install before trying to start the dev server using php artisan serve. You might also have to generate the key using php artisan key:generate incase the app starts with errors.

Natation answered 19/7, 2021 at 19:26 Comment(0)
H
0

I encountered same issues I hope this solution help someone else:

1. Delete the **vendor** folder/directory of the project
2. run **"composer install"** to install packages.

That fixed my issues.

Hardspun answered 18/1, 2022 at 11:0 Comment(0)
C
0

I've solved this issue by searching the process that was keeping open the file sf_proc_00.err within %LOCALAPPDATA%\Temp (the local Windows temp directory). Process Explorer or similar tools can be used for this. It was locked by ssh.exe (very likely launched by git). After killing the process, composer runs normally again.

Chilpancingo answered 31/3, 2022 at 13:0 Comment(0)
D
0

Just Stop/Shoutdown Artisan Server

It's work for me

Disembroil answered 23/7, 2022 at 18:49 Comment(0)
C
0

I have downgraded my PHP v8 to v7.4 and it works

Consignor answered 4/5, 2024 at 6:53 Comment(0)
I
0

just kill the current php process on Windows:

Click the Start charm.

Run "Windows PowerShell" as admin

run

Get-Process -Name php

to get Id then run

taskkill /PID <Id> /F
Incorrect answered 23/8, 2024 at 7:29 Comment(0)
U
-1

You should clear the config cache using optimize:clear command:

php artisan optimize:clear
Udall answered 2/3, 2021 at 13:45 Comment(0)
E
-1

The solution is very easy, just do

php artisan config:clear

Then rerun

php artisan serve
Engdahl answered 10/4, 2021 at 13:4 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.