Hi!
On server A I have some PHP files I want to run from server B via cron job. The problem is that these files are very big and are executing very long. The php.ini max_executon_time on server A (where the PHP script are ti be executed from server is not big enough so the scripts are able to complete their jobs. I have also SAFEMODE restriction limit on this server, therefore I can not increase the time limit of the scripts adding the line ini_set(max_execution_time) to them. So, what am I asking is:
Is there any way when starting the CRONJOBS form server B to set time limits for the scripts on the other server that are to be executed by that cron, so they to able to finish their work?
How can I do this?
Thanks in advance!
[RESOLVED] Set time limit for PHP script via cronjob
Try something like:
/usr/bin/php -d max_execution_time=300 myscript.php
And you suggest that I put that line in the top of my cron file or where?
Well that'd be the syntax I would try using in your cron job to execute the script.
Haven't messed with cron jobs in ages, so I'm afraid I can't be any more specific than that.
files called from the command line have no time out by default, are your sure its a time out issue? how are you calling the server b scripts?
Well, I was told the same in another one forum, but it seems to be not true, because I am calling all the big files without any success and also a simple script with one line representing the mail() function. All the files are not being executed finally except the mail script. Here is the code:
MAILTO=admin@livescore-bg.net
30 * * * * curl –silent –compressed /usr/bin/php -d max_execution_time=300 http://mysite-bg.net/file/file1.php
30 * * * * curl –silent –compressed /usr/bin/php -d max_execution_time=300 http://mysite-bg.net/file/file2.php
30 * * * * curl –silent –compressed /usr/bin/php -d max_execution_time=300 http://mysite-bg.net/file/file3.php
30 * * * * curl –silent –compressed /usr/bin/php -d max_execution_time=300 http://mysite-bg.net/file/file4.php
So am putting that code in a .txt file and via SSH I am typing crontab name of that file
P>S> I tried also that code before the one below:
MAILTO=admin@livescore-bg.net
30 * * * * curl –silent –compressed http://mysite-bg.net/file/file1.php
30 * * * * curl –silent –compressed http://mysite-bg.net/file/file2.php
30 * * * * curl –silent –compressed http://mysite-bg.net/file/file3.php
30 * * * * curl –silent –compressed http://mysite-bg.net/file/file4.php
...Oh. Now I understand what you're trying to do; guess I didn't read your first post entirely.
If you're using curl to execute the script remotely via HTTP, then of course there's nothing you can do to change the execution time (or any other PHP directive) on the remote server. Are you sure there's no way you can modify PHP directives on server B (such as by using a .htaccess file)? If so, then it sounds like you should find a decent host that can at least meet its customers' needs.
OK, see, I have no idea of cronjob and I have just read an article that showed me that code for starting remote files. Is there any other way than curl to call them from cron, if you think with curl there is no way the problem to be resolved?
Well it's not curl itself that's the problem, it's the whole manner in which you're going about executing the file. If it's a remote file, e.g. a file on a different server, then pretty much the only way you can execute the file directly is via an HTTP request. Obviously, there's no way to change PHP directives via an HTTP request (otherwise I'd be able to modify things on your server from my computer - somewhat of a security risk, no doubt).
I'm not sure what else to suggest, other than finding a decent host that meets your needs.
OK, thanks. I will mark the thread as resolved, as it looks like there is no solution for it.