Search code examples
phpfwrite

Create file with fwrite and use it immediately


I have a script that creates a file using fwrite and right after creating it it sends and email with this file anexed.

When I run this script I get an error "File does no exists". When I run the script again it all works.

So I guess that it tries to send the file to fast after creating it and the server maybe needs a few more ms before being able to send it.

Does anyone know this problem? Any solutions?


Solution

  • Delays should not be necessary; it is possible your script does not close the file, but PHP and other script languages will auto close open file handles at the end of execution, which means that the file will exist for the second run.