Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:06:18+00:00 2026-05-26T04:06:18+00:00

Using set_time_limit() or max_execution_time , does not really limits (except on Windows) the execution

  • 0

Using set_time_limit() or max_execution_time, does not “really” limits (except on Windows) the execution time, because as stated in PHP manual:

Note:

The set_time_limit() function and the configuration directive
max_execution_time only affect the execution time of the script
itself. Any time spent on activity that happens outside the execution
of the script such as system calls using system(), stream operations,
database queries, etc. is not included when determining the maximum
time that the script has been running. This is not true on Windows
where the measured time is real.

A solution is proposed in PHP comments to have a “real” execution time limit like what I’m looking for, but I found it unclear/confusing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:06:19+00:00Added an answer on May 26, 2026 at 4:06 am

    I might be wrong, but as far as I understand you ask for explanation of the “PHP comments” solution code.

    The trick is to spawn a child process, using pcntl_fork function, which will terminate the original (parent) process after some timeout. Function pcntl_fork returns process id of newly created child process inside a parent process execution thread and zero inside child process execution thread. That means parent process will execute the code under if statement and the child process will execute code under else. And as we can see from the code, the parent process will perform endless loop while child process will wait 5 seconds and then kill his parent. So basically you want to do something like this:

    $real_execution_time_limit = 60; // one minute
    
    if (pcntl_fork())
    {
        // some long time code which should be
        // terminated after $real_execution_time_limit seconds passed if it's not
        // finished by that time
    }
    else
    {
        sleep($real_execution_time_limit);
        posix_kill(posix_getppid(), SIGKILL); 
    }
    

    I hope I’ve exlained it well. Let me know if you sill have question regarding this solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send hundreds of emails using PHP. To increase the execution time,
I know that PHP CLI is usually used because of none time limits and
I'm using the WinAPI to set the time zone on a Windows XP SP3
Consider a normal PHP image upload functionality (not using AJAX) and there occurs this
FastCGI servers, for example, impose an execution time limit on PHP scripts which cannot
i am developing a online test website using PHP. i have set time limit
I'm using the following function that changes a calendar selection at a set time
I'm having trouble using os.utime to correctly set the modification time on the mac
Regardless of what the user's local time zone is set to, using C# (.NET
I have a class where I'm using __set . Because I don't want it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.