-1
I have a file php that gives a file_get_contents in archives json.
PHP can see the files because the file_exists works just right.
But if I give file_get_contents in the same file as the file_exists PHP returns me:
error 500 (internal server).
<?php 
date_default_timezone_set('America/Sao_Paulo'); $jogosF = 1; $datadehj = date("Y-m-d"); $horaAgora = date("H:i"); $array = array(); $tempo = (10 * 60); while(file_exists("../../../txts/bkpjogosF". $jogosF .".json")) {
$conteudo = file_get_contents("../../../txts/bkpjogosF". $jogosF .".json");
$conteudo = json_decode($conteudo);
foreach ($conteudo->data as $jogosDia) {
    if($jogosDia->odds->data != null) {
        $dataInicio = $jogosDia->starting_date;
        $horaInicio = $jogosDia->starting_time;
        if ($datadehj == $dataInicio && ((strtotime($horaAgora) + $tempo) < strtotime($horaInicio))) {
            $idMatch = $jogosDia->id;
            $timeCasa = $jogosDia->homeTeam->name;
            $escudoCasa = $jogosDia->homeTeam->logo;
            $timeFora = $jogosDia->awayTeam->name;
            $escudoFora = $jogosDia->awayTeam->logo;
            foreach ($jogosDia->odds->data as $oddses) {
                foreach ($oddses->types->data as $joOdds) {
                    if ($joOdds->type == "1x2") {
                        $bookmakerId = $oddses->bookmaker_id;
                        foreach ($joOdds->odds->data as $jogum) {
                            switch ($jogum->label) {
                                case 1:
                                $cotationC = $jogum->value;
                                break;
                                case 2:
                                $cotationF = $jogum->value;
                                break;
                                case "X":
                                $cotationEmp = $jogum->value;
                                break;
                            }
                        }
                        break 2;
                    }
                }
            }
            $datas = new DateTime($dataInicio);
            $horas = new DateTime($horaInicio);
            $horaInicio = $horas->format('H:i');
            $dataInicio = $datas->format('d/m/Y');
            $array[] = array(
            "horaI" => $horaInicio,
            "DataI" => $dataInicio,
            "timeCasa" => $timeCasa,
            "timeFora" => $timeFora,
            "idPartida" => $idMatch,
            "cotTimeC" => $cotationC,
            "cotEmp" => $cotationEmp,
            "cotTimeF" => $cotationF,
            "escudoC" => $escudoCasa,
            "escudoF" => $escudoFora,
            "bookmaker" => $bookmakerId
            );
        }
    }
}
$jogosF++;
fclose($handle); } $sorteador = usort($array, "Meusort"); echo json_encode($array); function Meusort($a, $b) { if($a == $b) { return 0; } return ($a<$b)?-1:1; } ?>
Note: The folder on the server has chmod -R 777 file, ie full permission. I have tried using the fopen, and made the same mistake.
On LOCALHOST with XAMPP it works.
And which error is returned?
– gmsantos
What version of your PHP on the server? Wouldn’t it be 5.3? Can you download the logs generated by
error_log=(php.ini) from php?– Guilherme Nascimento
"GET https://site.com 500 (Internal Server Error)"
– Krint
Possibly unhandled rejection: {"data":"","status":500,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"_classes/gamesBack.php","headers":{"Accept":"application/json, text/Plain, /"}},"statusText":"Internal Server Error"}
– Krint
These errors return me in the console and my php version is 5.0
– Krint
The error that php returns to you, not the request @Krint status code. If you are running in production, try enabling php’s bug report
– gmsantos
You mean the log? I’m trying to find
– Krint
usually apache saved in /var/logs/, but it helps if you put the following at the beginning of the script:
ini_set( 'error_reporting', E_ALL );
 ini_set( 'display_errors', 'On' );
 ini_set( 'track_errors', 'On' );– Karl Zillner
it might have nothing to do with file_get_contents, if it’s enabled in php.ini... then we’ll only know with the error log
– Karl Zillner
Opa, returned me the error and I discovered that it was because the memory was exhausted, I searched and put this command line ini_set("memory_limit", "256M"). Now it worked. Thank you!!!
– Krint