IamCavic
IamCavic

Reputation: 368

How to run a PHP script / function on shared hosting so that it doesn't time out?

I have a website on shared hosting, that I would like to run some reports on eg. performance, maybe send emails to all "non activated account", or report about their account to users.

So the issue is obvious if I just hit a URL some of these scripts will definitely time out and not finish.

I am not sure how to approach this problem, I have no access to SSH so I can't execute it via command line.

What are my other options? And if you can direct me in a way where I will be able to learn this.

Upvotes: 0

Views: 498

Answers (1)

Muhammed
Muhammed

Reputation: 1612

You could set max_execution_time, and memory_limit via ini_set(), since they are both PHP_INI_ALL. On the top of your script write this:

<?php
ini_set('max_execution_time',200); //in seconds
ini_set('memory_limit', "100M"); //in megabytes, change to your needs

For unlimited use, remove limits, use with caution, preferably for debugging only:

  • memory_limit set to -1
  • max_execution_time set to 0

Note that this setting will only affect your current PHP script, not other scripts, and it won't affect your database timeouts, or anything else you are doing there.

Upvotes: 1

Related Questions