Skip to content
Advertisement

How can I make my server allow my PHP script process to run for 75 minutes instead of disconnecting after only 45 minutes?

I am trying to save an mp4 file from audio live stream by PHP script initiated by cron job.

It’s expected to work for 75 minutes, but the problem is it runs for only 45 minutes. I found that the server may disconnect the process and not allow the script to run for such a long time.

I checked my PHP ini settings from CPanel and I found this:

JavaScript

This is my PHP script:

JavaScript

Advertisement

Answer

The problem is because of shared server hosting limitations. The shared server does not allow any script to run for more than 45 minutes (VPS & dedicated run normally).

I get around this issue by run 2 separate cron jobs (40 minutes between every job) instead of one big one.

  • The 1st job creates a file and saves data to it.
  • The 2nd job appends data onto the same file for the rest of stream duration.

Every script works for 40 minutes only in order to avoid the server killing the script.

Here is my final code:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement