Jump to content

[SOLVED] Is it possible to prevent script hanging during FTP upload?


Helmet

Recommended Posts

Hi,

 

I'm wondering what my options are if I need to upload a file and don't want that process to cause my script to hang (it's a signup script with file upload, but file must then be ftp'd to a different server). I'm thinking the only options are process forking or cron, but thought I'd tap into the freaky wisdom.

 

Thanks,

H

You can have a separate php file for the process you want to run in the background and use shell_exec() to call it.

http://www.php.net/manual/en/function.shell-exec.php

 

But I guess there's no way I can use this to pass values to a function in a separate file, correct? The problem is that I'm processing the image, and then I need to pass its name, location etc to the ftp uploading function.

 

If it's not possible to use shell_exec, what about something like this? I've never tried passing vars in an file include call:

 

include("http://www.mysite.com/index.php?filename=myfile.gif&location=/path/to/file");

 

Why wouldn't it be possible to use shell_exec()? Look into $argv: http://www.php.net/manual/it/reserved.variables.argv.php

 

Also, I had a crazy idea, but I've never tested it. If you send a location header in the middle of your code, it will change the page, but the script will finish on the server. Try something like this:

//upload checking code or whatever
header("Location: newpage.php");
move_uploaded_file([...]);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.