PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2012, 05:37 PM
teeheiman teeheiman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 9 teeheiman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 2 sec
Reputation Power: 0
Background Process

Hi, im writing a script that does a lot of image resizing and capturing a few photos from video.

I am using a background process to run the script.

My question is, the script at sometimes may run for 12-24 hours at a time.

Will the script time out if its ran to long? or do background process's run for ever?

Heres how I start it.

PHP Code:
function backgroundProcess($Command$log)
{
    global 
$basepath;
    if(
is_writable($basepath '/admin/logs/'.$log)) {
        
        
$PID shell_exec("nohup $Command > logs/".$log." & echo $!");
        return(
$PID);
    } else {
        return(
"Log file not writable! Cannot start background process! Please chmod 777 or delete /scripts/$log");
    }
}

if(
$_SERVER['REQUEST_METHOD'] == "POST")  {
        
$query mysql_query("select running from status");
        
$row mysql_fetch_array($query);
        if (
$row['running'] == 0) {
            
$pid backgroundProcess("$php_path $basepath/admin/process-cron.php","process.txt");
            
$msg "<p>The process is now running $pid</p>"
            } else {
            
$error "<p>The processor is already running.</p>"
        }




Thanks
-Billy

Reply With Quote
  #2  
Old October 30th, 2012, 10:28 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,939 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 9 h 13 m 20 sec
Reputation Power: 7053
It should run indefinitely.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old October 31st, 2012, 12:33 PM
henryc07 henryc07 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 15 henryc07 New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 3 h 49 m 21 sec
Reputation Power: 0
You could setup a cron job? If not, and it must be called within PHP i have once emulated it in a cross platform way without having access to exec() etc by using curl (believe it or not).

Create the .php script and make it public, and add this to the top:

if (isset($_POST['key']) == false || $_POST['key'] != 'your secret key') {
die(); //request not allowed
}

then from the other PHP file, create a secure (https) curl connection and POST the secret key to it, set a timeout on curl of say 5 seconds (you can also send a http close connection header from the request page) so that the calling script wont freeze if the request takes to long to complete, in your case 30 seconds.

This will do the follow: 1. curl will access the page securely (stops just anyway accessing it in their browser) 2. curl will wait 5 seconds, then close the connection (but BOTH your php scripts will carry on)

It's also compatible regardless of OS internals, shells, etc. You can also tweak the timeouts etc as u see fit.

Not a brilliant solution but hope it works well enough for you.

Reply With Quote
  #4  
Old November 1st, 2012, 01:47 PM
teeheiman teeheiman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 9 teeheiman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 22 m 2 sec
Reputation Power: 0
Awesome thanks for the help guys! I use to use the ASP forums here a lot, I was hoping all my rep would still be here. Oh well

Thanks again!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Background Process

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap