I have a function that writes it into a file.
public function write($type = "error", $mensaje = "") {
$this->file = fopen($this->filePath.$this->fileName, "a+");
if ($this->file == null) {
trigger_error("Error: No file", E_USER_ERROR);
} else {
fwrite($this->file, $type." ".$mensaje."
");
}
}
I need to call this function from another php file say index.php
function test() {
write("testing done");
echo "done";
}
I want the write function to be called from index.php asynchronously so the current execution doesn't stop or block if the write fails.
with phptreads ( http://php.net/manual/en/intro.pthreads.php ), something like
class writerThread extends Thread {
public function __construct($type="error",$message=''){
$this->type=$type;
$this->message=$message;
}
public function run(){
file_put_contents($filename,$this->type.$this->message);
}
}
$writer=new WriterThread("testing done");
$writer->start();