I want to run a php script in centos ( /usr/bin/php file.php ), and it takes long time to execute,and in the middle of executing , it stops running , and does not give me any errors. and I'm sure that there is absolutely no error in my php code (I tested it in many way) , I think it's the matter of time of executing.
my question is :

  • is it possible that it's timeout error from my server that stops the script from executing ?
  • if yes, how can I set the server to gives timeout error in a longer time?



2 Answers 2


Any PHP script executed from the command-line or from a shell script, cron job, etc. does not have a timeout.

You can't even deliberately set a max execution time when you're invoking PHP from the CLI. You can call set_time_limit(n) but this has no effect.

For example, if the max_execution_time affected the CLI, the following script should not print "done" but it does:


print ini_get('max_execution_time') . "\n";
print "done.\n";

It's possible that you have an error that is not being reported. Make sure you enable full error reporting:

  • but I'm sure that my php script gas no error, I just don't know why it stops after some minute, are you saying there is NO time out error in running a php script on command line or cron job ? Commented Nov 3, 2013 at 17:46
  • That was the point of my code example above. Even if you try to make the script have a timeout, it won't work if you invoke the script from the command-line. Commented Nov 3, 2013 at 18:09
  • so what do you think about my problem ? consider my script without error Commented Nov 3, 2013 at 18:29
  • You haven't shown your script or your usage of it. Commented Nov 3, 2013 at 19:35
  • its complicated and its in my own framework, you cant understand the code well,its about 180 lines, thanks by the way. Commented Nov 3, 2013 at 19:40

If you are sure there is no error in your script and you are running it from the command line, here are some things you could do:

  1. Test your theory about timeout: write a dummy script that does nothing for a very long time (like a nested loop), does it stop before it's done?
  2. Profile your code's memory requirements: https://github.com/arnaud-lb/php-memory-profiler.
  3. Try running the same script: though unlikely, there might be a problem with the Environment.

There is no reason that you shouldn't be able to run a script if there are no errors and the needed resources are available.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .