0

I am trying to sync folders between my remote server and amazon s3 using the system command through a php web page. The web page has option to browse the folder which need to sync between the server and s3

The s3 command is the below one

system('s3cmd sync '.$fldr_name.' '.BUCKET_NAME.' --config="'.AWS_CONF_FILE.'"',$return);

For small folders it is working . But I am syncing large file web pages connection is resetting .

I tried this on my php script

ignore_user_abort(true);

But no luck. Is there any way to make the webpage executable for a long time?

Thanks,

Anish
  • 4,262
  • 6
  • 36
  • 58

1 Answers1

0

The approach you're using is not ideal. The connection to the server might be resetting for several reasons when it's kept open for a long time, and some of these are out of your control.

I suggest you take another approach to this:

Queue all these sync tasks on the server and only execute a couple of them in parallel using a service that runs in the background (e.g. cron job or other).

When one of these syncs finishes, you record its success/failure in a database.

Then, in the UI, you regularly pull a second service (via AJAX calls executed at regular intervals) that checks the database and returns the pending/success/failure flag that you're storing. If the request is still pending, you simply recheck later.

dcro
  • 13,294
  • 4
  • 66
  • 75
  • Thanks for replying . I already have a cron script to sync between my folder. But what I am creating is an on demanding process that means if an user need to sync folder immediatly then they can use this webpage. For that purpose I am creating this one. – Anish Aug 27 '13 at 06:10
  • You can still make it on demand with the approach I suggested if your background service is notified when something is added to the queue or it checks that queue at very small time intervals. If you use your original approach and you have several users that simultaneously request an on-demand sync, some of those syncs will probably fail because of timeout issues. Also, on long open connections the connection might be closed because of an issue with your user's network and in that scenario they would never see if the sync was successful or it failed. – dcro Aug 27 '13 at 06:18
  • ok . Then I'm thinking of implementing with nohup and ajax based UI. But only thing the user wont get the alert on the screen . For that I can send an email notification. – Anish Aug 27 '13 at 06:34