Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, June 11, 2012

Fatal error: Maximum Execution Exceeded in PHP

Problem: Using PHP you just encountered an error similar to the following:

Fatal error: Maximum execution time of 30 seconds exceeded

Solution: Just add these line of code in your PHP file

$durationInSeconds = 60;
ini_set('max_execution_time', $durationInSeconds);

The code above gives the maximum execution time of 60 seconds for your PHP script. Just be warned that your script may hog your system if it is running a heavy process for a long time.

In case you want your script to run in an unlimited amount of time, just set zero to $durationInSeconds:

$durationInSeconds = 0;
ini_set('max_execution_time', $durationInSeconds);

Saturday, October 8, 2011

Redirect to Login Page in Wordpress

Using PHP, you can use the following code to redirect a user to the log-in page before being able to access a page. It will go to the page the user is trying to access once he is logged-in.

<?php auth_redirect() ?>

Some say it doesn't work right for logged-in users.
Better add a checking just to make sure it works all the time:

<?php
  if ( !is_user_logged_in() ) {
    auth_redirect();
  }
?>