What is the best way to do 1 way sync on PHP ?
New on LowEndTalk? Please read our 'Community Rules' by clicking on it in the right menu!

What is the best way to do 1 way sync on PHP ?

As of right now, I am zipping the remote folder, download that zip to local, and extract it. Surely there must be a better way to do it.

Comments

  • szarkaszarka Member
    edited August 12

    It's not clear to me what you are asking.

    If you're trying sync files from a Linux/Unix server, the most efficient way to do it would probably be rsync.

    But you asked specifically about PHP?

  • Yes, I asking specifically using php.

    Plenty of solution using vps / cli. But most shared hosting doesn't let you do it. So I resort to php only.

  • Upload 'rsync' binary and use PHP to chmod +x the rsync binary. Then invoke the rsync binary from PHP using exec or something.

    Bored developer: https://nulldev.xyz/

  • szarkaszarka Member

    Well, if you don't have an ssh login and you have a lot of data, then I guess have your server-side script find files modified since the last backup date and just zip those? Seems like the best answer to this is just "get a better hosting account or self-host", though.

  • Plenty of solution using vps / cli. But most shared hosting doesn't let you do it. So I resort to php only.

    I am also looking for a similar PHP based script solution for the above reasons. In addition some shared hosters disable PHP "exec" for additional security and then you really are chellenged! I haven't found anything yet but I keep looking.

  • szarkaszarka Member

    I don't think you need exec to walk the file directory, check file modification times, and build an archive. You could have your script put the incremental backup file in a web-accessible but password-protected directory, then just have a script on the target host wget and unarchive it. A little janky, and maybe not such great security, but...

    If you don't care about saving on bytes transferred, it's easier, because you don't have to track last backup time and check file modification dates. But same general idea.

  • What I want to achieve is 1 way sync. So, zipping the whole folder is the way to go for now. I wish there are some more elegant way to do this.

    I have a VPS and I named it Sync Server. My client in the other hand (using normal shared hosting with all limitation impose to them) need to sync the asset (picture, mp3, and stuff) from my Sync Server.

  • It sounds like ownCloud or Nextcloud would do the trick, but I guess that you don't want either of these for independent reasons ...

    An ångström is one ten-billionth of a meter.

  • using term '1 way sync' confusing people who want to help you.

    I thing what you want is a way to upload all your file to backup server using PHP script.

    Read about ziparchive http://www.php.net/manual/en/ziparchive.addglob.php

    upload these file to root folder then download from your 'backup/sync server' or using PHP to upload via SFTP then use crontab to delete these backup files

  • @angstrom said: It sounds like ownCloud or Nextcloud would do the trick, but I guess that you don't want either of these for independent reasons ...

    I am open to suggestions, as long as my client can duplicate my folder into their shared Hosting, is own cloud and next cloud can be synced into shared Hosting ?

  • pbgbenpbgben Member, Provider
  • @pbgben said: Ftp??

    PHP can do ftp client ?

  • @pbgben said: Ftp?? dont wasted too much time here, he need spoon-feed solution

  • No really, can php ftp download folder recursively ? Appreciate if anyone can point me to some link.

  • @yokowasis said: No really, can php ftp download folder recursively ? Appreciate if anyone can point me to some link.

    You can list all files and for folders, list directory of the folder and keep doing until you get all files link.

    Maybe there would be better solutions, a wrapper perhaps. I don't think its correct way to do this since php isn't made for this purpose.

    Manage Unlimited VPS/Servers for $10/month Click for 14 days trial Free SSL, Cache, Multiple PHP, Database and One-Click Installer - RunCloud

  • @jetchirag said:

    @yokowasis said: No really, can php ftp download folder recursively ? Appreciate if anyone can point me to some link.

    You can list all files and for folders, list directory of the folder and keep doing until you get all files link.

    Maybe there would be better solutions, a wrapper perhaps. I don't think its correct way to do this since php isn't made for this purpose

    It didn't really need ftp to do this. Actually it is a good idea.

  • Yup, got it working

    Thanks

    @jetchirag said:

    @yokowasis said: No really, can php ftp download folder recursively ? Appreciate if anyone can point me to some link.

    You can list all files and for folders, list directory of the folder and keep doing until you get all files link.

    Maybe there would be better solutions, a wrapper perhaps. I don't think its correct way to do this since php isn't made for this purpose.

  • @yokowasis said: Yup, got it working

    Thanks

    @jetchirag said:

    @yokowasis said: No really, can php ftp download folder recursively ? Appreciate if anyone can point me to some link.

    You can list all files and for folders, list directory of the folder and keep doing until you get all files link.

    Maybe there would be better solutions, a wrapper perhaps. I don't think its correct way to do this since php isn't made for this purpose.

    =)

    Manage Unlimited VPS/Servers for $10/month Click for 14 days trial Free SSL, Cache, Multiple PHP, Database and One-Click Installer - RunCloud

Sign In or Register to comment.