0

My server has a lot of photos saved. I would like to archive (.zip) those photos and download it from the server. I have created a PHP script to make archive those photos into a .zip file and download it.

If I execute that file directly through the browser, it's getting a timeout error. So I have created a CRON job to execute the script. But I only need to execute the CRON job whenever I need it. (Like clicking a button to execute the script).

Thanks for all the help!

7
  • 1
    …the whole point of cron is to schedule things to run at a particular time. Triggering a cron job when you click a button doesn't make any sense. I guess maybe you just want a way to run a job in the background, possibly without a timeout? Commented Nov 29, 2016 at 2:27
  • What is your command for crone ? Please add command here. Commented Nov 29, 2016 at 2:27
  • php /XXX/XXX/public_html/cli.php /cron_v2/index - 0 1 * * * this will working . Actually I need call the file whenever I click any button . Thank you. Commented Nov 29, 2016 at 2:31
  • Thank Mr Chris , Is there any option control the crone Job through php scripts. Actually I Need the run a job in background without timeout . Thanks. Commented Nov 29, 2016 at 2:35
  • @sathivel, again, trying to "control a cron job" from PHP doesn't make any sense. Forget about cron. Instead, you should be asking how to run your code. Commented Nov 29, 2016 at 2:42

1 Answer 1

1

See the set_time_limit function to prevent your timeout error.

http://php.net/manual/en/function.set-time-limit.php

As for running a cron as-needed, that isn't how a cron works. A cron executes a command at a set interval. A PHP script can include code to exit immediately if it's processing isn't needed. You will need to create some way to signal to the script if it needs to run or not. You could do this by updating a file or database record.

Alternatively you can use an application server to execute commands (scripts) as-needed via web service calls. PHP doesn't have good support for multi-threading which is needed for most application servers so you will likely need to use Java, Python, or Ruby to create web services to launch scripts as-needed in real time. You can then call these web services from PHP using cURL functions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.