Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/162140-running-a-php-script-without-the-user/
Share on other sites

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. 

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.