Viewed   58 times

I know that PHP CLI is usually used because of none time limits and primary because it is not using Apache threads/processes.

But is there any way how to explicitly set the max_execution_time for some scripts which i don't want to have the freedom of "unlimited time" and just want to keep those script under control?

If you think this question may be better answered on superuser.com and have permission to move it, do it. :)

Edit: I've been Googling a bit and found the right parameter:

php -d max_execution_time=5 script.php

 Answers

1

The documentation says that when running in command line mode, the default is 0 (unlimited). It doesn't say that you cannot override it:

set_time_limit(10); // this way
ini_set('max_execution_time', 10); // or this way

Edit: I just tried it myself, and it works as expected.

F:devwww>c:php -f index.php
PHP Fatal error:  Maximum execution time of 2 seconds exceeded in F:devwwwindex.php on line 3

Fatal error: Maximum execution time of 2 seconds exceeded in F:devwwwindex.php on line 3
Tuesday, November 15, 2022
2
  • How use cURL library when running PHP through Command Line

you need first to install cURL

  • http://curl.haxx.se/docs/install.html
  • http://it.php.net/features.commandline [via Web Archive]
Wednesday, September 28, 2022
 
hackbod
 
21

The shell/OS imposed limit is usually one or two hundred thousand characters.

getconf ARG_MAX will give you the maximum input limit for a command. On the Debian system I currently have a terminal open on this returns 131072 which is 128*1024. The limit is reduced by your environment variables and if my memory serves me correctly these are passed in the same structure by the shell, though that will only take off a few hundred characters in most cases. To find an approximation of this value run env | wc -c - this suggests 325 characters at the current time on this login on this machine.

Scripts are likely to permit this full length, but it is not unlikely that other utilities will impose their own limits either intentionally or through design issues. There may also be artificial limits to how long an individual argument on a long command line can be, and/or how long a path to a file can be.

Tuesday, August 16, 2022
25

I use

macaddr=$(echo $FQDN|md5sum|sed 's/^(..)(..)(..)(..)(..).*$/02:1:2:3:4:5/')

The benefit of this method, over a completely random number, is that it's possible to reliably reproduce the MAC address based on the FQDN of the machine, which I find useful sometimes. The 02 for the first octet just sets the "locally assigned" bit, which makes it obvious that it's not a vendor-provided MAC address, and guarantees that you won't collide with a real NIC's MAC address.

If you need to generate multiple MAC addresses per host, I used to concatenate the FQDN with the name of the bridge to connect the interface to; this did a good job of spreading things out for different NICs.

Wednesday, November 16, 2022
 
jdejuan
 
10

From the docs:

By de, nginx removes all environment variables inherited from its parent process except the TZ variable.

As you mentioned, you've tried setting them in the fastcgi config, which is, I think, the best you can do in this situation. For others' benefit this is done like this:

location ~ .php$ {

    # ...
    fastcgi_param APPLICATION_ENV "production";
    fastcgi_param MY_OTHER_ENV "things";
    include fastcgi_params;

    # ...
}

I understand the aversion to 'copy-paste', and agree! You should look at using a configuration management tool such as Puppet, SaltStack, Ansible to manage your config files. That way you can easily sync your environment variable list between all required locations. Let me know if you need more info about this.

Thursday, November 17, 2022
 
hugmeir
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :