1

Im using laravel to pull some log information from a database, but all of a sudden its stopped working, as in its not retrieving data and not returning anything. Im using vuejs to retrieve the data without page refresh, theres no problem on the front end because data can still be retrieved also in the chrome debug console its displaying as a 500 error.

Furthermore what i find weird is it works locally but not in production.

Example code of what works and what doesn't

 <?php

namespace App\Http\Controllers;

use App\Log;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class LogController extends Controller
{

    public function getLogData()
    {

          //This is the original code & it doesn't work in production! 
          //$data = Log::orderBy('id', 'DESC')->select('action', 'object_id', 'ip_address', 'user', 'time', 'date')->get();

        //This works! But only retrieves 1 row of information
        $data = Log::where('id', 1)->get();

        $data = str_replace('*', "<b>", $data);
        $data = str_replace('^', "</b>", $data);

        return $data;
    }

}

and heres the logs model, which shouldnt really affect anything but entering data into the database really but just incase anyone needs this information.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Log extends Model
{
    protected $fillable = ['action', 'object_id', 'object_type', 'ip_address', 'user', 'time', 'date'];
}

Any help i get will be appreciated.

Kenziiee Flavius
  • 1,918
  • 4
  • 25
  • 57
  • For 500 errors, look at your log in `storage/logs`. I'm guessing that you may need to re-order your Log statement: select, then orderBy, then get. – aynber Jan 05 '17 at 14:02
  • `$data = Log::where('id', 1)->get();` will retrieve only the entry with ID = 1. What error do you get, when you try the original query in production? – Peon Jan 05 '17 at 14:02
  • @aynber if this is the case then for 1 why does it work locally and two why has it worked for the past six months and then randomly stopped, ive not touched the logging system of this website for a few months. Ill check the logs though and get back to you! – Kenziiee Flavius Jan 05 '17 at 14:04
  • @DainisAbols I think you didn't read the question properly – Kenziiee Flavius Jan 05 '17 at 14:04
  • No idea, that's why it was a guess. I know my system gets a little finicky when I mix up the order of the commands. Have you looked at the log? – aynber Jan 05 '17 at 14:06
  • Yeha just had to pull it from the live version with filezilla, the log is showing me that the last error that was logged is from a month ago :/ there is no 2017 activity here – Kenziiee Flavius Jan 05 '17 at 14:09

2 Answers2

1

The answer to this question can be found here in detail: Limit on amount of rows retrieved MySql, Laravel

In short my Mysql query was pulling back more than my set limit of data due the the growing daily data of my logs table. Increased the limit and everything was working as usual.

Community
  • 1
  • 1
Kenziiee Flavius
  • 1,918
  • 4
  • 25
  • 57
0

I would check the php5 error file, check your php.ini for the location of the error file on the production machine. 500s missing in the logs endup in the php error file log sometimes. There can be a memory leak e.g a string too long for php memory to process it since its returing a log entry which can sometimes be long.

Also, Can you make the select statement as the first thing that you pass to the model like this (won't solve the issue at hand but its best practice to do so )

Log::select('action', 'object_id', 'ip_address', 'user', 'time', 'date')
     ->orderBy('id', 'DESC')
     ->get();
Tariq Khan
  • 5,498
  • 4
  • 28
  • 34