asmith Posted June 14, 2009 Share Posted June 14, 2009 Hi, I have upload page when a user upload his file. when he uploads the file I will show him : "file uploaded successfully" But I need to do some operations on the file after without the user running a script. Is it possible to do such thing? to say it more simple : 1. user uploads the file and must see the "successful" page and he is done here, he can do whatever he wants. (maybe close his browser) 2. When server recieved the file, it runs the script which will do some operations on the file. I'm asking this, because the process may take 20 sec or more. and If I do the operation with the user viewing the page, I'm actually making the user wait for 20 sec. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/ Share on other sites More sharing options...
Mark Baker Posted June 14, 2009 Share Posted June 14, 2009 Run a cron job that looks for newly uploaded files and performs the necessary functions on that file Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855586 Share on other sites More sharing options...
asmith Posted June 14, 2009 Author Share Posted June 14, 2009 Yea I thought of that. but still, doing the file after the user uploads is very better. Are you saying its not possible? Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855601 Share on other sites More sharing options...
.josh Posted June 14, 2009 Share Posted June 14, 2009 well something has to execute the script. If it's done through a request, the user will have to wait around until it's done, as it would make the request and wait for a response. Only other way is to get the server to do it independently of the user, which would be by setting up a cronjob. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855615 Share on other sites More sharing options...
Daniel0 Posted June 14, 2009 Share Posted June 14, 2009 Actually, you could make the user request spawn an additional process and just move on. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855616 Share on other sites More sharing options...
.josh Posted June 14, 2009 Share Posted June 14, 2009 I thought that wasn't possible with php? Like, I know you can do forking..sort of..but that's not really the same thing.. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855619 Share on other sites More sharing options...
Daniel0 Posted June 14, 2009 Share Posted June 14, 2009 Well, I think pcntl_exec doesn't wait for the process to finish. I'm not entirely sure though. It's not available on Windows though. Edit: Wait, no, it says "Executes specified program in current process space". I just thought there was some function that could do that. Maybe I'm wrong. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855631 Share on other sites More sharing options...
cunoodle2 Posted June 14, 2009 Share Posted June 14, 2009 it is possible to open up said page with curl in the background? Set the timeout at 30 seconds. I don't know that it would still keep working if they closed their browser window or not. It would be worth the try to see what happens. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855735 Share on other sites More sharing options...
asmith Posted June 14, 2009 Author Share Posted June 14, 2009 Background? How do you open a page in the background? Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855741 Share on other sites More sharing options...
cunoodle2 Posted June 14, 2009 Share Posted June 14, 2009 This would open the page but print nothing to the screen. Again I'm not sure if closing the browser would kill the script or not but it may be worth a try.. <?php $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.yoursite.com/process.php"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_TIMEOUT, 120); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); $buffer = curl_exec($ch); curl_close($ch); ?> That would store the value of the page within the "$buffer" variable (if needed). Again I don't know that it will keep processing but try it out. Also is it possible to create something (via JavaScript or something that prevents the user from closing the browser??). I feel like I remember seeing that. You could just keep them on the page or something along those lines. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855748 Share on other sites More sharing options...
Daniel0 Posted June 14, 2009 Share Posted June 14, 2009 That could actually work (like one second, or even lower if it allows that). Set a really low timeout and then use ignore_user_abort on the called script. Quote Link to comment https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/#findComment-855751 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.