Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the finish with file_put_contents() in php?

Tags:

file

php

detect

In PHP, i will write (create) the file using file_put_contents($filename, $data);
It is ok, but i want to detect the finish event of process.

Currently, the page is showing loading status.
This is currently the way i can know it is finish or not.

I want to detect with the code.

like image 370
Alvin Avatar asked May 22 '11 00:05

Alvin


People also ask

What is the use of file_put_contents in PHP?

The file_put_contents() function in PHP is an inbuilt function which is used to write a string to a file. The file_put_contents() function checks for the file in which the user wants to write and if the file doesn't exist, it creates a new file.

How can I get the content of a file in PHP?

The file_get_contents() reads a file into a string. This function is the preferred way to read the contents of a file into a string. It will use memory mapping techniques, if this is supported by the server, to enhance performance.

How can check file in folder in PHP?

The file_exists() function checks whether a file or directory exists. Note: The result of this function is cached.


2 Answers

This is a blocking, I/O call, so it finishes when the function call returns. The return value is the number of bytes written (upon success).

like image 99
AJ. Avatar answered Oct 07 '22 06:10

AJ.


It puts everything on hold until it's over

So you could use something like this to determine when it has finished writing the file.

echo "The file's contents are now being written, please wait.";
file_put_contents($filename, $data);
echo "The file's contents have been written.";
like image 22
Travis Avatar answered Oct 07 '22 07:10

Travis