Need to run a long php script from a browser

Active3 hr before
Viewed126 times

4 Answers


Generally, these kinds of tasks take a long time to execute and are not suited to running in a web environment since they cause timeout errors.,When it comes to running PHP scripts on the command line, you should be aware of the location of the PHP executable file in your PHP installation.,other general-purpose tasks,As we discussed earlier, command-line PHP scripts are generally used for routine application-specific tasks, like:

phpinfo() is a very useful function that gives you information about your server and PHP setup. Let’s create a phpinfo.php file under the htdocs directory with the following contents:

< ? php
phpinfo(); ?
load more v

Prerequisite required:You have already a custom php.ini file set up in your application or a request has to be done to the owner who maintains it. If some of the PHP scripts take longer time then the server stops and throws an error:,This article describes how to change or control the maximum execution time of a PHP script.,Maximum execution time taken by a PHP Script,It is used when you need to override the configuration value at run-time. This function is called from your own PHP code and will only affect the script which calls this function. Use init_set(‘max_execution_time’0) when you want to set unlimited execution time for the script.

Prerequisite required:
You have already a custom php.ini file set up in your application or a request has to be done to the owner who maintains it. If some of the PHP scripts take longer time then the server stops and throws an error:

Fatal error: Maximum execution time of ..seconds exceeded in this_file.php on line...
Maximum execution time of each script, in seconds;
http: //
Note: This directive is hardcoded to 0
for the CLI SAPI
max_execution_time = 4000
php_value name value

This sets the value for that particular directive as specified.

php_value max_execution_time 200
load more v

So what gives? You installed PHP locally and ran your script without problem, but a web browser wasn’t involved,Instead, you need PHP on a web server. It’s the web server—not the web browser—that can interact with a PHP interpreter. Your browser can handle HTML on its own, but it has to make a request to a web server to deal with PHP scripts. That server can take your PHP scripts and run them, and then take the response and send it back to your browser. Your browser can then understand and handle the response.,The web server gives the browser back something that the browser can understand: the HTML result of interpreting a PHP script, or CSS, or JavaScript, or a combination of all of the above.,A web browser makes a request for some page. That page might be a URL on a remote web server, or a local file on your computer.

<link rel="stylesheet" href="styles/mysite.css" type="text/css" />
<link rel="stylesheet" href="styles/mysite.css" type="text/css" media="all" />
<link rel="stylesheet" href="styles/print.css" type="text/css" media="print" />
load more v

Next, add the following code to send a sample text message:,Most developers will spend time Googling workarounds instead of focusing on the fact that this behavior is not a bug. In reality, people shouldn’t wait a whole minute or more for your page to load or process to complete within the browser. It’s just not an ideal user experience.,New PHP developers may not be aware that every script you run has 30 seconds to complete. If your API requests, database transactions, and data processing don’t complete in time, you will experience a server timeout. This is because PHP's max_execution_time helps prevent poorly written scripts from tying up the server.,In a subsequent post, I will show you how to process 1000 or more messages within this 30 second window using Twilio Notify.

$ touch script - time.php
load more v

Other "script-undefined" queries related to "Need to run a long php script from a browser"