Q: How do I log a specific value/error into a separate text file in PHP? I'm currently working on syncing datas on my mobile app and my web app, and I'm having a problem with it. I want to make sure if the data from my mobile app is really sending data to my web app by logging each of these datas into a separate text file. Same as with the web app, I want to know if how much of the data it is receiving and how much it is storing into the database.
Like for example, in javascript we have console.log()
note: I'm using MVC framework
This is my idea so far in debugging the problem. If you do have any better ideas, reply with your comments below.

A: This is how to do basic logging in PHP. Also, depends on how you're receiving the data, but if it's one call at a time, I'd use a time stamp to make a new file name for each unique data piece. I assume your incoming data is in the variable $data.
file_put_contents("mydata" . time(), $data, FILE_APPEND);


A: This task can be handle from many ways,
1) Why you are logging into a separate file, you can send your request from client(mobile) as a response,
<?php print_r($_POST); ?>

This will return your request as a response...! This will works like,
console.log();

2) You can save the request into your database creating a testing table in which you can saved the complete request from the client side after that view your data in phpMyAdmin
3) To write the separate file you can use below code,
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "Your Client Data\n";
fwrite($myfile, $txt);
fclose($myfile);
?> 


A: If you want to create a new file with your data just put these few lines
$myFile = "testFile.txt"; 
$fh = fopen($myFile, 'w') or die("can't open file"); 
$stringData = "YOUR DATA\n"; 
fwrite($fh, $stringData); 
fclose($fh); 

The $fh variable contains the file handle for testFile.txt.
