简体   繁体   English

如何不受所有限制地运行php脚本?

[英]How to run php script without all limits?

I know there are many questions, how to run php script without time execution limit, but im curious, how to run php script without any limitations. 我知道有很多问题,如何不受时间限制地运行php脚本,但我很好奇,如何不受任何限制地运行php脚本。 (i think there is something like max memory consumption, mysql timeout, etc...) (我认为有一些事情像最大内存消耗,mysql超时等...)

I have script, which is mapping my part of harddrive and reading directory and files content and storing some data into database. 我有脚本,该脚本映射硬盘驱动器的一部分并读取目录和文件内容,并将一些数据存储到数据库中。 So im expectating that this script will take long time and huge chunk of memory. 因此,我期望此脚本将花费很长时间并且要占用大量内存。

So my question is, what should i set to "infinite" to get script running maximum posible duration? 所以我的问题是,我应该将什么设置为“ infinite”以使脚本运行最大可能的持续时间?

as for now, im using this ini_set, but for some reason script ends before everything is finished. 就目前而言,即时通讯使用此ini_set,但是由于某些原因,脚本在完成所有操作之前就结束了。 (and even before 40 minutes time limit which i set) (甚至在我设定的40分钟时限之前)

ini_set('max_execution_time', 2400);
ini_set('display_errors',1);
ini_set('mysql.connect_timeout', 2400);
ini_set('default_socket_timeout', 2400);

There's no way to unset all limit at once. 无法立即取消所有限制。

The best you can do is to look at all the php.ini directive and try to figure out which applies to your system, and increase them to an unlimited value, or when not applicable, a very big value. 最好的办法是查看所有php.ini指令,并尝试找出适用于您的系统的值,并将其增加为无限值,或者在不适用时增加为非常大的值。

Here's a list of the core PHP directives: https://secure.php.net/manual/en/ini.list.php 这是核心PHP指令的列表: https : //secure.php.net/manual/en/ini.list.php

You have to remember that there's limit on the system too (ulimit on Linux) that can prevent the PHP process to grab enough memory / open enough files. 您必须记住,系统上也有限制(在Linux上为ulimit),这会阻止PHP进程获取足够的内存/打开足够的文件。

Here's the ulimit doc: http://ss64.com/bash/ulimit.html 这是ulimit文档: http : //ss64.com/bash/ulimit.html

Don't for forget they vary from user to user. 不要忘了它们因用户而异。


Also, you could run your script with PHP-CLI (from a command line) as it doesn't have any limits enforced by the web server. 另外,您可以使用PHP-CLI(从命令行)运行脚本,因为它没有Web服务器强制执行的任何限制。

In your php.ini make max_execution_time = 0 在您的php.ini中,使max_execution_time = 0

Note: But it is not a good practice. 注意:但这不是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM