0

I have seen this question on here before so I am sorry for the repetition but I have still not found an answer to my problem.

I have a bash script that takes a while to run. It needs to be passed variables set by a user on a webpage (don't worry there will be plenty of validation for security etc)

I can get the bash file to start but it dies after 20 seconds maybe when run from the webpage.

When run from the terminal.. runs absolutely fine.

Ok so I have the following:

$bashFile = shell_exec('./CoinCreationBashFile.sh "'.$coinName.'" "'.$coinNameAbreviation.'" "'.$blockReward.'" "'.$blockSpacing.'" "'.$targetTimespan.'" "'.$totalCoins.'" "'.$firstBitAddy.'" "'.$seedNode.'" "'.$seedName.'" "'.$headline.'" ');

Now this executes the bash file, but I read up about Shell_exec php with nohup and came up with the following:

$bashFile = shell_exec('nohup ./CoinCreationBashFile.sh "'.$coinName.'" "'.$coinNameAbreviation.'" "'.$blockReward.'" "'.$blockSpacing.'" "'.$targetTimespan.'" "'.$totalCoins.'" "'.$firstBitAddy.'" "'.$seedNode.'" "'.$seedName.'" "'.$headline.'" >/dev/null 2>&1 &');

But this still died after short time :(

So read up about set_time_limit and max_execution_time and set these to like 10000000 in the php.ini file.... Yet still no joy :(

Just want to run a bash script without it timing out and exiting. Don't really want to have to put an intermediate step in there but someone suggested I look at ZeroMQ to "detach worker from process" so I may have to go this route.

many thanks in advance

1 Answer 1

1

dont try runging a script via browser if they take more then 60 seconds instead try running this with SSH or as a cronjob.

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

3 Comments

I can pass variables to the cronjob from the php page? and this was NOT useful... stackoverflow.com/questions/4918982/… any answer to that?
can't do a cron job as i don't want to periodically run it... need to run on request
For anyone else who stumbles on this scenario, my workaround was to get the php page to write the necessary variables to a small .txt file in a usually empty directory. Then setup a cron job to check if this directory contained a file. Extract the variables and run the script as root from the cron job. Really not to much work once figured out. Many thanks for the advice Ethan

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.