PHP: set_time_limit() has no effect

PHP: set_time_limit() has no effect

Posted by: Hervard
Posted on: 2007-06-23 05:54:00

I'm trying to limit the maximum execution time of one of my PHP scripts using set_time_limit(1), but it does not seem to have any effect.

PHP's manual states the following:

"[The set_time_limit() function] has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini."

Does Dreamhost have PHP running in safe mode? I'm on Fiji. Am I able to have a php.ini file for myself to edit? Is there any other way to limit my script's maximum execution time?

Any assistance in this matter would be greatly appreciated -- thanks in advance :)

Re: PHP: set_time_limit() has no effect

Posted by: Mousee
Posted on: 2007-06-23 06:03:00

You can't set PHP settings without changing the PHP.ini file on DreamHost, and thus this wiki article comes in handy. Let us know if you need any help with it wink

Re: PHP: set_time_limit() has no effect

Posted by: Hervard
Posted on: 2007-06-23 06:33:00

Thanks for the link :)

However, I only want to change the max_execution_time setting for one script, not for everything.

Am I out of luck?

...or, if I end up having php.ini and php.cgi in my home directory, would set_time_limit() work?Edited by Hervard on 06/23/07 06:43 AM (server time).

Re: PHP: set_time_limit() has no effect

Posted by: Mousee
Posted on: 2007-06-23 06:47:00

Well with the php.ini, in the case of that wiki link, you're using DreamHost's own setup - so you wouldn't actually be changing anything other than the options you want, which is quite cool! And yes, you can change *just* the time limit, which would be this setting from within the php.ini file:

In reply to:


max_execution_time = 120


Re: PHP: set_time_limit() has no effect

Posted by: Hervard
Posted on: 2007-06-23 06:53:00

Ideally I would like to just call the set_time_limit() function within my single script to change the max_execution_time setting for one script.

I'm wanting to to change the max time to 1 second, and this probably wouldn't be a good thing for my other scripts, which is why I'm wary of editing php.ini to do this.

Would copying over Dreamhost's php.ini to my home dir and editing my .htaccess file (as stated in the Wiki page) allow set_time_limit() to work when called in my script, or would that still have no effect?

Re: PHP: set_time_limit() has no effect

Posted by: Mousee
Posted on: 2007-06-23 07:38:00

Ahhh, well unfortunately this method will affect all of your scripts, and I'm unaware of how to avoid that. There's really no better solution though that I'm aware of for your situation, other than to use the Custom PHP.ini method as explained in the wiki article.

In reply to:


Would copying over Dreamhost's php.ini to my home dir and editing my .htaccess file (as stated in the Wiki page) allow set_time_limit() to work when called in my script, or would that still have no effect?


I've already explained this - Yes, it will work just fine.

Re: PHP: set_time_limit() has no effect

Posted by: Hervard
Posted on: 2007-06-23 07:41:00

Ah, I must've misinterpreted your post.

Thanks for your help -- I'll give it a try :)

Re: PHP: set_time_limit() has no effect

Posted by: rlparker
Posted on: 2007-06-23 11:23:00

One possible work around to have the custom php.ini setting only effect the single script is to run that script from its own subdomain (which can have it's *own* php setup). wink

--rlparker

Re: PHP: set_time_limit() has no effect

Posted by: rockinbassman
Posted on: 2007-06-23 20:09:00

Since you're declaring the PHP to run as your custom setup in .htaccess, couldn't you put the script in a separate directory with an .htaccess telling all PHP scripts in that directory only to run with the custom php.ini setup. That way only that directory is affected.

Re: PHP: set_time_limit() has no effect

Posted by: rlparker
Posted on: 2007-06-24 01:22:00

I don't see any reason why not (I only mentioned *one* workaround - yours may well be better)! wink

--rlparker

Re: PHP: set_time_limit() has no effect

Posted by: misterhaan
Posted on: 2007-06-25 07:56:00

actually you can change php settings in php code, just not this specific setting. i change include_path and session.cookie_domain that way and both of those work.

track7 - my dream-hosted site

Re: PHP: set_time_limit() has no effect

Posted by: Mousee
Posted on: 2007-06-25 08:59:00

Oh indeed there are some settings you can change, just not many, and definitely not via .htaccess in this case smile

Tags: maximum execution timetime limitset timesafe modegreatly appreciatedphp scriptsdreamhostini fileworkaroundthanks in advance