-1

I have page, in which are a lot of sites, with their source codes, i need to synchronize them to ftp, one site, has its own ftp. Im using FTPsync class. It is working very good, files are going to FTP but problem is when i clicking on "Push files to FTP", then my main site is freezed until ftp synchronization process is done, can anyone say to me, what is the problem ? why that is happening, and maybe offer how can i solve this. Thanks.

If FTPsync class source code is needed, let me know i will add it here.

Gntvls
  • 230
  • 4
  • 16
  • Your question doesn't include enough details. What is "hangs"? Is it hanging from one machine only? At what point does it hang? See [session\_start hangs](http://stackoverflow.com/questions/4333209/session-start-hangs) for exmample. If you're going to show code, show the generic outlines. The FTPSync class is the less interesting one. – CodeCaster Oct 16 '13 at 08:47

1 Answers1

0

If you're performing the FTP syncing process within the same request, then yes your page will take a very long while to load and might interfere with other requests as well.

The suggested way of doing this is usually to make a job queue, in which you can use a storage system (database, etc) or a message queue to queue the jobs, and write another script to perform the syncing.

If you want an easier way to solve this, you can just

  1. Use ignore_user_abort() and flush to cut away the user connection and continue the syncing in the background
  2. Embed a frame within the page which is performing the action and show a progressbar. Then at the end of the sync do a window.parent.location = 'done-syncing'

For 1., here's an example:

<?php
ignore_user_abort(true);
ob_start();
echo 'Syncing...';
ob_end_flush();
flush();

// Perform the FTP syncing here

For 2., it will span across multiple pages. Suppose clicking on "Push files to FTP" brings you to a page ftp_sync_start.php, and then the file which does the real syncing is ftp_do_sync.php, then here are some examples:

ftp_sync_start.php

<!-- You can put some sort of progress bar here -->
<iframe src="ftp_do_sync.php?<?php // Pass some parameters here ?>"></iframe>

ftp_do_sync.php

<?php
// Just do the syncing here, then at the end
echo "<script>window.parent.location = 'ftp_sync_done.php';</script>";

These solutions are not too scalable though.

TheOnly92
  • 1,723
  • 2
  • 17
  • 25