The ini_set
, according to its own documentation
Sets a new value for the specified configuration option. The configuration option will keep the new value during script execution and will be restored at the end of script execution.
That is, when executing a script, if the directive is defined ini_set
, it will alter temporarily the value set and once the execution is finished it will return to the initial value. then, you need to use it when starting the execution of a script.
Suppose the following route on the Laravel
Route::get('/', 'HomeController@index')->name('home');
In the controller I must define the ini_set
thus
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function index() {
ini_set('max_execution_time', 5);
/* ... */
}
}
when calling the method index
the value of max_execution_time
will be amended.
Or change this value through construtor
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
public function __construct() {
ini_set('max_execution_time', 5);
}
public function index() {
/* ... */
}
}
thus the call of any method of HomeController
will change the value of max_execution_time
.
Where are you putting this ini_set?
– JrD
In the class I am running, in this case it is the class that processes the file.
– Filipe L. Constante
tries with php’s Sleep function => Sleep(5);
– denis
Right, but with Sleep, it will stop for 5 seconds and then back, I need to really error the application if it passes the informed time. In my case, if it takes more than five seconds, it’s because there’s something very wrong, you understand?
– Filipe L. Constante
It depends on where in this class you are applying, because if you only use one method of it she will not even see this ini_set. Either you add to the constructor or in the method body
– JrD
Yes, I call a method straight out, in case I do not add the constructor no. In this case, there is another alternative p/ setar this guy?
– Filipe L. Constante
Get it, see if this link helps you ! https://laracasts.com/discuss/channels/general-discussion/maximum-execution-time-of-30-seconds-exceeded?page=1
– denis
Okay, I will try, but here the company blocks the registration. Anyway thanks. I will continue searching too.
– Filipe L. Constante
I don’t know exactly what the final reason you want to reach, but if possible you could use Symfony Process (https://symfony.com/doc/current/components/process.html) to run the script as a separate process and set a timeout in it.
– Pedro Henrique
Peter, it would be ideal, but the "deadline" does not allow, the quickest way I found was this. However, for now without success.. :(
– Filipe L. Constante