title: How to log Request and Errors on a PHP webservice without using any framework
body: <ol>
  <li>I am developing a PHP backend API server for a web application,
  which contains more than 50 PHP API's. </li>
  <li>Now what I need is that I
  need to log all requests comes and errors occur to these API's. </li>
  <li>I am not using any framework.  </li>
  <li>I have created my own code for logging
  the request which is given bellow.</li>
  </ol>
  
  <p>// **************PHP API Request Log Code*****************</p>
  
  <p>function log_data
      {</p>
  
  <pre><code>$req_dump = json_encode($_REQUEST);
  
  $actual_link = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  
  $filename = str_replace(" ", "_", $_FILES['userfile']['name']);
  
  
  $log  = "------------------------------------------------------------".PHP_EOL.
  "UserIP: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
         "Request Data: ".$req_dump.PHP_EOL.
         "Request Method: ".$_SERVER['REQUEST_METHOD'].PHP_EOL.
         "API URL: ".$actual_link.PHP_EOL.
         "File Name: ".$filename.PHP_EOL.
         "------------------------------------------------------------".PHP_EOL;
  }
  
  
         // $fp = fopen('../api_logs/request.txt', 'a');
         // $fw = fwrite($fp, $log);
         // fclose($fp);
         $fp = file_put_contents( '../api_logs/request.log', $log, FILE_APPEND);
  
  // **************PHP API Request Log Code*****************
  </code></pre>
  
  <ol start="5">
  <li>Now what is the best method to log all API's request information and Error logs together into a file on the server itself?</li>
  </ol>