How do you get a Cronjob executing a PHP script to run longer than 30 seconds?

How can I rewrite this into a cron that will run every day for longer than 30 seconds? Also, do I need to edit the .htaccess or php.ini file in the cron.php directory to say something? Over the browser it runs just fine for longer than 30 seconds; over the shell, it runs just fine too. But as a cron set task, it dies after 30 seconds. I'm on 1and1 share hosting.

0 12 * * * php5 /this/is/the/file/cron.php


There are several things that could be terminating your script. One could be the maximum execution time set in the php.ini file. If that's the case, you can override it in your script with set_time_limit(0); where zero means no limit and any number greater than zero is the number of seconds to allow the script to run for before being terminated. It's important to note that this time does NOT include the time it takes for the browser to make the request, so file upload time wouldn't count here.

If you're in a shared hosting environment (like Dreamhost), they have process watches that will kill off any PHP process after a set time limit. You cannot get around these. You would need to contact the hosting provider to see what you need to do to get access to run the script for longer (for Dreamhost, they want you to have a they're PS offering).


Use this syntax to start php:

php -c /path/to/another/php.ini /this/is/the/file/cron.php

Then you can specify a different timeout (or no timeout) in a different php.ini file.


ini_set('max_execution_time', 600);

Add this to the top of your php file and it will run for 600 seconds. Anything more is not recommended but you can have a go if you want.


I would just use wget http://path.to.myscript.php

If it's dying after 30 you may need to set max_execution_time = 60 in your php.ini to allow the script to run longer than 30 seconds.


You could also use ini_set('max_execution_time', 60)

But as the manual page says, in some cases (i.e. running in safe mode) this will have no effect at all: http://uk.php.net/manual/en/info.configuration.php#ini.max-execution-time

It could also be possible that the php.ini for client line has different max execution values than for the browser. I have seen it sometimes.


  • Converting an array with 50,000+ entries into a mysql database
  • How to use PHP to parse large XML file sequentially
  • Extract text from a DIV that occurs on multiple pages on a website, then output to .txt?
  • my php script stops exactly after 120 seconds
  • Can't add target for UIButton - unrecognised selector sent to instance, despite method been in
  • Laravel routes overwriting phpmyadmin path with nginx
  • Laravel routes not found on nginx
  • Is need install mysql on AWS EC2 if i am using AWS rds as database instance?
  • C++, user input check for '\\0' stops at spaces?
  • K Shortest Path Python Not Working
  • How do I configure Maven Cargo to use an embedded Tomcat server?
  • PHP in userdir not working
  • unrecognized selector isPitched called
  • What is the equivalent of Android permissions in iOS development? [duplicate]
  • how to read a file in prolog?
  • Thread synchronization with syncwarp
  • Redshift Querying: error xx000 disk full redshift
  • Bash if statement with multiple conditions
  • How to remove a SwiftyJSON element?
  • Swift: Switch statement fallthrough behavior
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • DomPDF {PAGE_NUM} not on first page
  • Update CALayer sublayers immediately
  • Javascript simulate pressing enter in input box
  • JFileChooser in front of fullscreen Swing application
  • Does CUDA 5 support STL or THRUST inside the device code?
  • When should I choose bucket sort over other sorting algorithms?
  • Importing jscolor library in angular 2
  • How to make Safari send if-modified-since header?
  • How do you troubleshoot character encoding problems?
  • How to pass list parameters for each object using Spring MVC?
  • A cron job substitute?
  • Understanding cpu registers
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • JaxB to read class hierarchy
  • failed to connect to specific WiFi in android programmatically