Errors from background jobs

LiteCart Fan
Depuis France
Membre depuis janv. 2015

Hi TIM.
Here is a part of my log.

[18-Oct-2017 13:06:54 Europe/Paris] Warning: set_time_limit(): Cannot set max execution time limit due to system policy in ~/admin/modules.app/run_job.inc.php (Line 2)
 ← ~/admin/index.php (Line 121) in include()
Request: GET /admin/?app=modules&doc=run_job&module_id=job_mysql_optimizer HTTP/1.1
Client: 195.220.159.34 (jonathan.enac.fr)
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36

[18-Oct-2017 13:10:44 Europe/Paris] Warning: set_time_limit(): Cannot set max execution time limit due to system policy in ~/admin/modules.app/run_job.inc.php (Line 2)
 ← ~/admin/index.php (Line 124) in include()
Request: GET /admin/?app=modules&doc=run_job&module_id=job_error_reporter HTTP/1.1
Client: 195.220.159.34 (jonathan.enac.fr)
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36

[18-Oct-2017 13:10:44 Europe/Paris] Fatal error: Invalid email address () in ~/includes/classes/email.inc.php (Line 21)
 ← ~/includes/functions/func_email.inc.php (Line 10) in set_sender()
 ← ~/includes/library/lib_functions.inc.php (Line 13) in email_send()
 ← ~/includes/modules/jobs/job_error_reporter.inc.php (Line 56) in __callstatic()
 ← ~/includes/modules/mod_jobs.inc.php (Line 30) in process()
 ← ~/admin/modules.app/run_job.inc.php (Line 9) in process()
 ← ~/admin/index.php (Line 124) in include()
Request: GET /admin/?app=modules&doc=run_job&module_id=job_error_reporter HTTP/1.1
Client: 195.220.159.34 (****)
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36

~/admin/modules.app/run_job.inc.php  => set_time_limit(60*5); is not supported
When I remove this line, the job module  can be configured, instead of an error in the browser too (Fatal error: Invalid email address () in ~/includes/classes/email.inc.php (Line 21)).
For the admin email, ouch, I didn't touch anything about that, and it's well configured !
I'm recieving sometimes a mail with the job result.

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

Are you on PHP safe mode? Its a bit unconventional to forbid use of set_time_limit()? What is the code your host uses to forbid it? That way I could add a condition before.

When it comes to the email address, there might be a bug inte current dev. But did you check the email address in the error reporter module settings?

LiteCart Fan
Depuis France
Membre depuis janv. 2015

No, of course not, I'm not in PHP safe mod.
I remember I've already seen this problem before but I just removed the line and error_job_reporter was working as it was intended to.
After the latest commits, as this mod was not included in my core vqmod, the error reappeared.
It's not a conventional error, but I can't modify php settings on my web host, except very few parameters via a .user.ini.

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

Could you ask your web host with which setting they enable this protection? So I can detect it from a condition.

LiteCart Fan
Depuis France
Membre depuis janv. 2015

Generally, set_time_limit() is disabled by web hosts for security reasons

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

Yes you mentioned that. How can I detect that before attempting to call the command?

LiteCart Fan
Depuis France
Membre depuis janv. 2015

I'm googling about that. Lots of people have this problem, with other CMS like wordpress for example.
When you put a @ before the line, it' just not executed.
I'm trying parameters via php.ini, but no way yet.

LiteCart Fan
Depuis France
Membre depuis janv. 2015

I've just tried this function in a new php file:

And, safe_mod is disabled on my web host.

LiteCart Fan
Depuis France
Membre depuis janv. 2015

A track start :
in php.ini (or .user.ini, depends on web host)
max_execution_time must be set to 0 to use set_time_limit().
In my case I used a value of 300.
It seems it causes problems with the php function set_time_limit().
With max_execution_time = 0, there is no more problems with litecart. BUT it could be a problem for other scripts, as everything is shared...

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

max_execution_time must be set to 0 to use set_time_limit().

  • Really?

And it's not in ini_get('disable_functions') ?

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini

When called, set_time_limit() restarts the timeout counter from zero.

http://php.net/manual/en/function.set-time-limit.php

LiteCart Fan
Depuis France
Membre depuis janv. 2015

I agree but, as usual, it's only a theory ! Web hosts do what they want !
With a value of max_execution_time defined in the php.ini (or .user.ini), in fact, you can't use set_time_limit() without a php error, like my logs for litecart.  On my web host in fact (the others, I  don't know). Trust me, my web site is well configured and optimized for best performance, I can mistake but I'm not a beginner.
So I disable the line cause I prefer having max_execution_time set. I've already seen that, as I said, with wordpress plugins or so on.
More over, max_execution_time = 300 is fully compliant with your line (60*5) : it's the same interval !
It's not a new error, I saw it before and just forgot to tell about that (all my hands and fingers are used !), and in the previous files, I removed the line too. 
Recently I crushed my litecart with the latest commit of 2.0.3, and this problem appeared again.

"max_execution_time must be set to 0 to use set_time_limit().

  • Really?"
    It seems so. I've tried that successfully, it's well documented on the web and it's a recurrent clue.

"And it's not in ini_get('disable_functions') ?" Where is that ?

For a detection before using the function, wow it's not easy I guess.

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

What is returned by this code?

Could you link me up to a reference saying max_execution_time must be set to 0 to use set_time_limit()?

What did your web host say about this setting? How did they set it? How do we identify it?

LiteCart Fan
Depuis France
Membre depuis janv. 2015

gives
string(100) "disk_total_space, diskfreespace, exec, system, popen, proc_open, proc_nice, shell_exec, passthru, dl"

LiteCart Fan
Depuis France
Membre depuis janv. 2015

For example a google search on "Warning: set_time_limit(): Cannot set max execution time limit due to system policy"

First result and links inside (and lots of other links in google results with the same complaint ...)
https://www.silverstripe.org/community/forums/general-questions/show/10952
exact case of mine
By my own experience, I know that Drupal, Prestashop and Wordpress are affected by this problem. 
Safe mod off.
Web host doesn't want to modify its configuration (I can understand that)

Scenario: 
php.ini with max_execution-time = 300 (good practice)
I must remove via a vqmod the line set_time_limit in run_job_inc.php, cause there's the warning in litecart or php logs
php.ini with max_execution-time = 0 or line emptied
No more error on set_time_limit in logs but I'm not able to know if it works

php setting is prior to any script. I'd rather keep max_execution-time = 300

Notice : most of users won't even see this problem, because you only see it when analysing logs !

tim
Founder
Depuis Sweden
Membre depuis mai 2013
tim

That link was regarding safe_mode and mentions nothing about max_execution_time must set to 0 to enable usage of set_time_limit().

Can you email me the results of the following code:

Ce fil de discussion a été fermé en raison d'une longue inactivité. Il n'est pas possible de publier dessus.
Ce site n'utilise aucun cookie ni aucune technologie de suivi tierce. Nous pensons pouvoir faire mieux que les autres et nous nous soucions vraiment de votre vie privée.