0

Moodle REST APIs failing intermittently and returning 500 (Internal Server Error)

Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

<?php
error_reporting(-1); // reports all errors
ini_set("display_errors", "1"); // shows all errors
ini_set("log_errors", 1);
ini_set("error_log", "php-error.log");
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * Version details
 *
 * @package    local_lingk
 * @copyright  (C) 2018 Lingk Inc (http://www.lingk.io)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
//require_once '../lib/moodlelib.php';
// require_once($CFG->dirroot.'/lib/moodlelib.php');
require_once($CFG->libdir.'/moodlelib.php');
require_once 'src/Mandrill.php'; //Not required with Composer

global $DB, $CFG, $SESSION, $USER;

$CFG = new stdClass();
$CFG->dataroot = '/usr/src/moodle/moodledata';
$CFG->cookiename = 'MoodleSession';

$USER = new stdClass();
$USER->id        = -10;
$USER->email     = 'emailed';
$USER->firstname = 'Do not reply to this email';
$USER->username  = 'noreply';
$USER->lastname  = '';
$USER->confirmed = 1;
$USER->suspended = 0;
$USER->deleted   = 0;
$USER->picture   = 0;
$USER->auth      = 'manual';
$USER->firstnamephonetic = '';
$USER->lastnamephonetic  = '';
$USER->middlename     = ''; 
$USER->alternatename  = ''; 
$USER->imagealt       = '';
$USER->maildisplay    = 1;
$USER->emailstop      = 1;


header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: access");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Allow-Credentials: true");
header('Content-Type: application/json');
header("HTTP/1.0 200 Successfull operation");
// echo '=============+++++++';exit;
    $wsfunction = $_POST['wsfunction'];   
    // print_r($record);exit;
    // $client_id = $_POST['client_id'];
    // $client_secret = $POST['client_secret'];
    // $device_id = $POST['device_id'];
    $response = array();

I tried changing apache config and mysql config but APIs are failing intermittently. It works 2 times and fails on 3rd and sometimes succeeds thrice and fails on fourth attempt. Am I missing any configuration or moodle setting?

nickalchemist
  • 2,211
  • 6
  • 31
  • 58
  • 3
    You need to investigate the errors. Check the server error logs, as well as PHP error logs. – Blue Aug 02 '18 at 20:14
  • I am not getting any error in ssl-error log. But I am getting it in access.log file. Only 500- internal server error. – nickalchemist Aug 02 '18 at 20:15
  • I am using Ubuntu and MySQL and application is hosted on cloud server with valid SSL certificate – nickalchemist Aug 02 '18 at 20:15
  • 1
    FWIW: https://stackoverflow.com/questions/4731364/internal-error-500-apache-but-nothing-in-the-logs You need to get the actual error, as is nothing to go on. – ficuscr Aug 02 '18 at 20:19
  • I tried all before posting here. Is there Moodle specific setting that I am missing? I am getting logs for other APIs – nickalchemist Aug 02 '18 at 20:22
  • Or some file write issue – nickalchemist Aug 02 '18 at 20:22
  • have you tried to delete this chunk `Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.30-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies` and everything before the ` – Evgeniy Voevodin Aug 03 '18 at 07:02
  • its php configuration. not part of php file – nickalchemist Aug 03 '18 at 08:45
  • There must be something specific that causes the 500 error. That should be in your apache error.log file. If you're not getting anything in there that tells you why you have the 500 error, go into Moodle and dial up the debugging level until you do - basically, just set it to "DEVELOPER" until you're done with this. – Martin Greenaway Aug 09 '18 at 09:57

0 Answers0