php debug with file logs

today i add third-party libraries class, this class stream output file,

because its output stream i cant debug it with show value in browser

i can’t get parameter value in process, and didn’t where error start …

lucky … php can write to file, so we can write value in file log and read it

i use CodeIgniter Framework, so i will show the controller class

first create folder and file

$ mkdir logs

$ touch logs/file.log

$ chmod -R 777 logs

now create class controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Debug extends CI_Controller {

public function index()
$debug = $this->input->get('debug');

if($debug) $handle = fopen( BASEPATH . "../logs/file.log", "a+");

$hello = "Hello From " . __FILE__ ;

if($debug) fwrite($handle, "\r\nlog ".date("Y-m-d H:i:s").": ".$hello);

echo $hello;

if($debug) echo "<br /> debug execute";

test with browser

call-debugopen the file log


and how to real time debug ???

open terminal, go to folder file.log  and type

$ tail -f logs/file.log


Published by


just to remember what i had known :)

One thought on “php debug with file logs”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s