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 8814347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:05:58+00:00 2026-06-14T04:05:58+00:00

I am coding a php script that does some back end stuff and needs

  • 0

I am coding a php script that does some back end stuff and needs to run every 8 hours or so. The script takes a while to execute. For the hell of it, I tried it from my browser and the connection to the server gets reset well before the script terminates. My question is – if I run it directly, ie. php -a file.php as a cron job, are there any internal time constraints on execution? This script may take 2-5 minutes to complete and cannot be interrupted. I’ve never done this before so I am not sure if php has quirks when running heavy scripts.

  • 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-06-14T04:05:59+00:00Added an answer on June 14, 2026 at 4:05 am

    As said before, CLI scripts by default have no time limit.

    But I would also like to mention an alternative to your cron job approach:
    You can fork a CLI PHP script from a PHP script under webserver control. I have done this many times. It is especially useful if you have a script with long execution time which must be triggered by some website user action (e.g. building a very large archive file and send a download link by email when the file is complete).
    I usually fork a CLI script from a webserver PHP script using the popen() function. This allows to nicely transfer parameters to the new script instance like this:

    $bgproc = popen('php "/my/path/my-bckgrnd-proc.php"', 'w');
    if($bgproc===false){
      die('Could not open bgrnd process');
    }else{
      // send params through stdin pipe to bgrnd process:
      $p1 = serialize($param1);
      $p2 = serialize($param2);
      $p3 = serialize($param3);
      fwrite($bgproc, $p1 . "\n" . $p2 . "\n" . $p3 . "\n");
      pclose($bgproc);
    }
    

    In the CLI script you would receive these params like this…

    $fp = fopen('php://stdin', 'r');
    $param1 = unserialize(fgets($fp));
    $param2 = unserialize(fgets($fp));
    $param3 = unserialize(fgets($fp));
    fclose($fp);
    

    …and do anything with them that would take to long under webserver control.

    This technique works equally well in *nix and Windows environments.

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

Sidebar

Related Questions

I'm trying to implement some kind of caching in a PHP script that will
A long shot but here's hoping someone has some experience coding PHP hooks for
I am coding in php, attempting to get the start\end dates and times for
I am working on some form coding in PHP, and I have everything working
I'm playing around with encrypt/decrypt coding in php. Interesting stuff! However, I'm coming across
I am coding a web application in PHP and it has some performance intensive
I have the following log in script that is run when a user hits
I'm writing a (PHP) script that serves files to the client. Among others, the
I'm wanting to setup a php script and host it on my server that
I have created a PHP script but while using it in my hosting server

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.