Re: [PHP] code deployment through php

2012-05-14 Thread rene7705
On Sun, May 6, 2012 at 3:32 PM, rene7705  wrote:
> On Sat, May 5, 2012 at 5:13 AM, tamouse mailing lists
>  wrote:
>>
>> On Wed, May 2, 2012 at 5:23 AM, rene7705  wrote:
>> > On Wed, May 2, 2012 at 11:47 AM, rene7705  wrote:
>> >
>> >> I can't use anything like git on my shared hoster. But I suppose I
>> >> could
>> >> use something like git at home, and use a sync script like I posted in
>> >> my
>> >> OP on the shared hoster.
>> >>
>> >>
>> >>
>> > Maybe you git gurus can help me along a bit further.
>> >
>> > I've managed to install msysgit and get it to work on my windows dev
>> > box,
>> > so far so good.
>> >
>> > Now, I'm wondering how to set up my repositories. The last cvs I used
>> > was
>> > Microsoft's visual source control back in the 90's, so I'm very rusty.
>> > At
>> > the same time, I'd prefer not to experiment too much..
>> >
>> > I've got a tree structure in a folder called simply "code", that I have
>> > in
>> > several locations on my windows box.
>> >
>> > Each site that I develop for has a folder in
>> > .../htdocs/sites/somedomain.com,
>> > and many of these sites will need a copy of the common "code" folder in
>> > them. I can restrict myself to developing in one domain's subdir only.
>> > The non-common code for each domain is designed to run from any
>> > $_SERVER['SERVER_NAME'] and any sub-directory it happens to be in. In
>> > other
>> > words, http://my-dev-box.biz/sites/somedomain.com/ will show the same
>> > thing
>> > from windowze as http://somedomain.com will from shared hosted linux.
>> >
>> > I would also like to version control the non-common code for each
>> > domain.
>> >
>> > And I would like to store the entire repository on my windows box at
>> > home
>> > in 2 or 3 specific locations (on seperate disks encrypted with
>> > truecrypt.org,
>> > and also a truecrypted usb disk, if and when that's plugged in).
>> >
>> > For distributing the common code to the shared hosted live server (my
>> > workflow is to check finalized changes on my win box against all my
>> > sites
>> > that used the common code base, before deploying to the shared hoster
>> > live
>> > server), I can simply FTP one finalized copy and use the simplest of rm
>> > -rf
>> > and cp -r commands in a short script to distribute the changes. I could
>> > even do without the PHP filesync code I posted earlier (altho it was fun
>> > to
>> > build! :)
>> >
>> > That darn hoster of mine won't support git on shared hosting, only on
>> > much
>> > more expensive virtual dedicated and dedicated plans :(
>> > But I've also found
>> >
>> > http://serverfault.com/questions/26836/setting-up-a-git-repo-on-my-godaddy-hosting-plan
>> >  and
>> >
>> > http://www.lyraphase.com/wp/uncategorized/how-to-build-git-for-a-host-with-no-compiler/
>> > that
>> > show me how I might get git running on my (kinda lame now) shared
>> > hosting
>> > account.
>> >
>> > Maybe a stupid question, but would perhaps copying the common code
>> > around
>> > with a simple script be faster than multiple pushes by git?
>>
>>
>> Using git, you can set up either publicly hosted repositories on
>> github.com or gitorious.org or perhaps other public repo places. If
>> you don't want you code to be publicly available, you can set up
>> private repositories as well.
>>
>> Not being familiar with Windows implementations much at all, I can't
>> tell you specifically what to do with msysgit, so these will be more
>> generic instructions.
>>
>> I'm going to assume you don't have a host somewhere with ssh access.
>> In this case you'll most likely want/need to set up your repository on
>> your local system. (Note that it isn't *strictly* necessary to have a
>> repository -- you can clone a new tree from the existing code tree,
>> however having a repository can ensure a clean code set in case your
>> working tree gets out of sync somehow.)
>>
>> (These instructions are modified from
>>
>> http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux
>> )
>>
>> First, create a directory you want to hold all of your local
>> repositories (such as C:\User\rene\MyRepositories). Then create a
>> subdirectory off that to hold your server/application common code
>> (C:\Users\rene\MyRepositories\commoncode).
>>
>> Make that directory (..\commoncode) a *bare* repository. (Not sure how
>> that's done with msysgit, but the basic git command is: "git init
>> --bare C:\Users\rene\MyRepositories\commoncode")
>>
>> Then you add the repository as a remote to the working tree: git
>> remote add origin C:\Users\rene\MyRepositories\commoncode
>>
>> Now you can push commits to your repository with the following sequence:
>>
>> git add 
>> git commit
>> git push origin master
>>
>> Now, to *deploy*, you can do the following:
>>
>> Somewhere outside your working tree, create a directory called "deploy":
>>
>> mkdir C:\Users\rene\deploy
>>
>> Then clone your the repository of your commond code:
>>
>> git clone C:\Users\rene\MyRepositories\commoncod

Re: [PHP] code deployment through php

2012-05-06 Thread rene7705
On Sat, May 5, 2012 at 5:13 AM, tamouse mailing lists <
tamouse.li...@gmail.com> wrote:

> On Wed, May 2, 2012 at 5:23 AM, rene7705  wrote:
> > On Wed, May 2, 2012 at 11:47 AM, rene7705  wrote:
> >
> >> I can't use anything like git on my shared hoster. But I suppose I could
> >> use something like git at home, and use a sync script like I posted in
> my
> >> OP on the shared hoster.
> >>
> >>
> >>
> > Maybe you git gurus can help me along a bit further.
> >
> > I've managed to install msysgit and get it to work on my windows dev box,
> > so far so good.
> >
> > Now, I'm wondering how to set up my repositories. The last cvs I used was
> > Microsoft's visual source control back in the 90's, so I'm very rusty. At
> > the same time, I'd prefer not to experiment too much..
> >
> > I've got a tree structure in a folder called simply "code", that I have
> in
> > several locations on my windows box.
> >
> > Each site that I develop for has a folder in .../htdocs/sites/
> somedomain.com,
> > and many of these sites will need a copy of the common "code" folder in
> > them. I can restrict myself to developing in one domain's subdir only.
> > The non-common code for each domain is designed to run from any
> > $_SERVER['SERVER_NAME'] and any sub-directory it happens to be in. In
> other
> > words, http://my-dev-box.biz/sites/somedomain.com/ will show the same
> thing
> > from windowze as http://somedomain.com will from shared hosted linux.
> >
> > I would also like to version control the non-common code for each domain.
> >
> > And I would like to store the entire repository on my windows box at home
> > in 2 or 3 specific locations (on seperate disks encrypted with
> truecrypt.org,
> > and also a truecrypted usb disk, if and when that's plugged in).
> >
> > For distributing the common code to the shared hosted live server (my
> > workflow is to check finalized changes on my win box against all my sites
> > that used the common code base, before deploying to the shared hoster
> live
> > server), I can simply FTP one finalized copy and use the simplest of rm
> -rf
> > and cp -r commands in a short script to distribute the changes. I could
> > even do without the PHP filesync code I posted earlier (altho it was fun
> to
> > build! :)
> >
> > That darn hoster of mine won't support git on shared hosting, only on
> much
> > more expensive virtual dedicated and dedicated plans :(
> > But I've also found
> >
> http://serverfault.com/questions/26836/setting-up-a-git-repo-on-my-godaddy-hosting-plan
> >  and
> >
> http://www.lyraphase.com/wp/uncategorized/how-to-build-git-for-a-host-with-no-compiler/
> > that
> > show me how I might get git running on my (kinda lame now) shared hosting
> > account.
> >
> > Maybe a stupid question, but would perhaps copying the common code around
> > with a simple script be faster than multiple pushes by git?
>
>
> Using git, you can set up either publicly hosted repositories on
> github.com or gitorious.org or perhaps other public repo places. If
> you don't want you code to be publicly available, you can set up
> private repositories as well.
>
> Not being familiar with Windows implementations much at all, I can't
> tell you specifically what to do with msysgit, so these will be more
> generic instructions.
>
> I'm going to assume you don't have a host somewhere with ssh access.
> In this case you'll most likely want/need to set up your repository on
> your local system. (Note that it isn't *strictly* necessary to have a
> repository -- you can clone a new tree from the existing code tree,
> however having a repository can ensure a clean code set in case your
> working tree gets out of sync somehow.)
>
> (These instructions are modified from
>
> http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux
> )
>
> First, create a directory you want to hold all of your local
> repositories (such as C:\User\rene\MyRepositories). Then create a
> subdirectory off that to hold your server/application common code
> (C:\Users\rene\MyRepositories\commoncode).
>
> Make that directory (..\commoncode) a *bare* repository. (Not sure how
> that's done with msysgit, but the basic git command is: "git init
> --bare C:\Users\rene\MyRepositories\commoncode")
>
> Then you add the repository as a remote to the working tree: git
> remote add origin C:\Users\rene\MyRepositories\commoncode
>
> Now you can push commits to your repository with the following sequence:
>
> git add 
> git commit
> git push origin master
>
> Now, to *deploy*, you can do the following:
>
> Somewhere outside your working tree, create a directory called "deploy":
>
> mkdir C:\Users\rene\deploy
>
> Then clone your the repository of your commond code:
>
> git clone C:\Users\rene\MyRepositories\commoncode cleancode-20120404
>
> Then you can ftp the contents of cleancode-20120404 to your server as
> needed.
>
> Sorry to be unable to tell you the exact steps with msysgit, but I
> hope you can interpolate from the comm

Re: [PHP] code deployment through php

2012-05-04 Thread tamouse mailing lists
On Wed, May 2, 2012 at 5:23 AM, rene7705  wrote:
> On Wed, May 2, 2012 at 11:47 AM, rene7705  wrote:
>
>> I can't use anything like git on my shared hoster. But I suppose I could
>> use something like git at home, and use a sync script like I posted in my
>> OP on the shared hoster.
>>
>>
>>
> Maybe you git gurus can help me along a bit further.
>
> I've managed to install msysgit and get it to work on my windows dev box,
> so far so good.
>
> Now, I'm wondering how to set up my repositories. The last cvs I used was
> Microsoft's visual source control back in the 90's, so I'm very rusty. At
> the same time, I'd prefer not to experiment too much..
>
> I've got a tree structure in a folder called simply "code", that I have in
> several locations on my windows box.
>
> Each site that I develop for has a folder in .../htdocs/sites/somedomain.com,
> and many of these sites will need a copy of the common "code" folder in
> them. I can restrict myself to developing in one domain's subdir only.
> The non-common code for each domain is designed to run from any
> $_SERVER['SERVER_NAME'] and any sub-directory it happens to be in. In other
> words, http://my-dev-box.biz/sites/somedomain.com/ will show the same thing
> from windowze as http://somedomain.com will from shared hosted linux.
>
> I would also like to version control the non-common code for each domain.
>
> And I would like to store the entire repository on my windows box at home
> in 2 or 3 specific locations (on seperate disks encrypted with truecrypt.org,
> and also a truecrypted usb disk, if and when that's plugged in).
>
> For distributing the common code to the shared hosted live server (my
> workflow is to check finalized changes on my win box against all my sites
> that used the common code base, before deploying to the shared hoster live
> server), I can simply FTP one finalized copy and use the simplest of rm -rf
> and cp -r commands in a short script to distribute the changes. I could
> even do without the PHP filesync code I posted earlier (altho it was fun to
> build! :)
>
> That darn hoster of mine won't support git on shared hosting, only on much
> more expensive virtual dedicated and dedicated plans :(
> But I've also found
> http://serverfault.com/questions/26836/setting-up-a-git-repo-on-my-godaddy-hosting-plan
>  and
> http://www.lyraphase.com/wp/uncategorized/how-to-build-git-for-a-host-with-no-compiler/
> that
> show me how I might get git running on my (kinda lame now) shared hosting
> account.
>
> Maybe a stupid question, but would perhaps copying the common code around
> with a simple script be faster than multiple pushes by git?


Using git, you can set up either publicly hosted repositories on
github.com or gitorious.org or perhaps other public repo places. If
you don't want you code to be publicly available, you can set up
private repositories as well.

Not being familiar with Windows implementations much at all, I can't
tell you specifically what to do with msysgit, so these will be more
generic instructions.

I'm going to assume you don't have a host somewhere with ssh access.
In this case you'll most likely want/need to set up your repository on
your local system. (Note that it isn't *strictly* necessary to have a
repository -- you can clone a new tree from the existing code tree,
however having a repository can ensure a clean code set in case your
working tree gets out of sync somehow.)

(These instructions are modified from
http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux
)

First, create a directory you want to hold all of your local
repositories (such as C:\User\rene\MyRepositories). Then create a
subdirectory off that to hold your server/application common code
(C:\Users\rene\MyRepositories\commoncode).

Make that directory (..\commoncode) a *bare* repository. (Not sure how
that's done with msysgit, but the basic git command is: "git init
--bare C:\Users\rene\MyRepositories\commoncode")

Then you add the repository as a remote to the working tree: git
remote add origin C:\Users\rene\MyRepositories\commoncode

Now you can push commits to your repository with the following sequence:

git add 
git commit
git push origin master

Now, to *deploy*, you can do the following:

Somewhere outside your working tree, create a directory called "deploy":

mkdir C:\Users\rene\deploy

Then clone your the repository of your commond code:

git clone C:\Users\rene\MyRepositories\commoncode cleancode-20120404

Then you can ftp the contents of cleancode-20120404 to your server as needed.

Sorry to be unable to tell you the exact steps with msysgit, but I
hope you can interpolate from the commands above.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] code deployment through php

2012-05-02 Thread Lester Caine

rene7705 wrote:

I can't use anything like git on my shared hoster. But I suppose I could
use something like git at home, and use a sync script like I posted in my
OP on the shared hoster.


I have some legacy hosting packages which are just ftp access and BC just lists 
them and allows me to manage things quickly when I need to update those sites. 
One of these days they will get moved to an easier location :)


--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] code deployment through php

2012-05-02 Thread rene7705
On Wed, May 2, 2012 at 11:47 AM, rene7705  wrote:

> I can't use anything like git on my shared hoster. But I suppose I could
> use something like git at home, and use a sync script like I posted in my
> OP on the shared hoster.
>
>
>
Maybe you git gurus can help me along a bit further.

I've managed to install msysgit and get it to work on my windows dev box,
so far so good.

Now, I'm wondering how to set up my repositories. The last cvs I used was
Microsoft's visual source control back in the 90's, so I'm very rusty. At
the same time, I'd prefer not to experiment too much..

I've got a tree structure in a folder called simply "code", that I have in
several locations on my windows box.

Each site that I develop for has a folder in .../htdocs/sites/somedomain.com,
and many of these sites will need a copy of the common "code" folder in
them. I can restrict myself to developing in one domain's subdir only.
The non-common code for each domain is designed to run from any
$_SERVER['SERVER_NAME'] and any sub-directory it happens to be in. In other
words, http://my-dev-box.biz/sites/somedomain.com/ will show the same thing
from windowze as http://somedomain.com will from shared hosted linux.

I would also like to version control the non-common code for each domain.

And I would like to store the entire repository on my windows box at home
in 2 or 3 specific locations (on seperate disks encrypted with truecrypt.org,
and also a truecrypted usb disk, if and when that's plugged in).

For distributing the common code to the shared hosted live server (my
workflow is to check finalized changes on my win box against all my sites
that used the common code base, before deploying to the shared hoster live
server), I can simply FTP one finalized copy and use the simplest of rm -rf
and cp -r commands in a short script to distribute the changes. I could
even do without the PHP filesync code I posted earlier (altho it was fun to
build! :)

That darn hoster of mine won't support git on shared hosting, only on much
more expensive virtual dedicated and dedicated plans :(
But I've also found
http://serverfault.com/questions/26836/setting-up-a-git-repo-on-my-godaddy-hosting-plan
 and
http://www.lyraphase.com/wp/uncategorized/how-to-build-git-for-a-host-with-no-compiler/
that
show me how I might get git running on my (kinda lame now) shared hosting
account.

Maybe a stupid question, but would perhaps copying the common code around
with a simple script be faster than multiple pushes by git?


Re: [PHP] code deployment through php

2012-05-02 Thread rene7705
I can't use anything like git on my shared hoster. But I suppose I could
use something like git at home, and use a sync script like I posted in my
OP on the shared hoster.


Re: [PHP] code deployment through php

2012-05-01 Thread Lester Caine

rene7705 wrote:

Well, I want to work on 1 copy of my common code on my windows machine,
then sync those changes to all my sites (hosted on the win dev box) to see
if it messes up the other sites, then FTP those changes to my hosting
account, and run the sync script there as well.


I have a number of windows based customers who also like to review what we are 
doing, so I ended up with HG. TortoiseHg provides a nice gui based DVCS system 
interface on Windows which works identically on Linux and I can push and pull 
changes around the place without having to worry about anything.


The servers 'pull' a copy of the code base from a local server master, which is 
managed from the development environment. Config information is protected on 
each site, and the whole thing works identically on both windows and linux so I 
don't have to worry what the customers are using. THEY can work to their own 
site and change what we give them access to, while the core code is managed from 
the central repo.


If they come up with something useful it can be merged back into the master copy 
:) One of the few pieces of software I actually pay for is BeyondCompare which 
provides the same cross platform facilities for merging files and with it's 
built in ftp interface allows manually inspecting the file structure on any of 
the machines. A couple of my Mac based customers are now investigating the same 
development base.


Add Eclipse/PHPEclipse on top and you have the ultimate cross platform IDE :)

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] code deployment through php

2012-05-01 Thread Larry Garfield

On 5/1/12 4:19 AM, rene7705 wrote:

On Tue, May 1, 2012 at 11:11 AM, Camilo Sperberg  wrote:


If I understood the problem correctly, you want to keep a single copy of
your code on every machine you work, including the final server.



Well, I want to work on 1 copy of my common code on my windows machine,
then sync those changes to all my sites (hosted on the win dev box) to see
if it messes up the other sites, then FTP those changes to my hosting
account, and run the sync script there as well.



Have you read about SVN ? You can set up a cronjob to execute it
automatically if you want, there are clients for Windows, Zend Studio, etc
etc.



I've read about some source control systems, I've tried them out, but I'd
rather go for this simpler approach tbh.
I already do regular backups that are timestamped, it's enough for me right
now I think.


No it's not.  Really.  For what you describe, a proper version control 
system is the correct tool.  Rolling your own with rsync and cron is 
setting yourself up for failure.


A couple people here have mentioned SVN.  I used to use SVN, but now 
have migrated everything I do to Git.  Without getting into a religious 
battle between Git and SVN, I do strongly recommend you look into it. 
This is an excellent resource for why to use it and how to use it:


http://progit.org/book

If you're serious about development, get serious about version control.

--Larry Garfield

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] code deployment through php

2012-05-01 Thread admin

-Original Message-
From: Stuart Dallas [mailto:stu...@3ft9.com] 
Sent: Tuesday, May 01, 2012 8:19 AM
To: rene7705
Cc: Camilo Sperberg; php-general
Subject: Re: [PHP] code deployment through php

On 1 May 2012, at 10:19, rene7705 wrote:

> On Tue, May 1, 2012 at 11:11 AM, Camilo Sperberg 
wrote:
> 
>> If I understood the problem correctly, you want to keep a single copy 
>> of your code on every machine you work, including the final server.
>> 
>> 
> Well, I want to work on 1 copy of my common code on my windows 
> machine, then sync those changes to all my sites (hosted on the win 
> dev box) to see if it messes up the other sites, then FTP those 
> changes to my hosting account, and run the sync script there as well.
> 
> 
>> Have you read about SVN ? You can set up a cronjob to execute it 
>> automatically if you want, there are clients for Windows, Zend 
>> Studio, etc etc.
>> 
> 
> I've read about some source control systems, I've tried them out, but 
> I'd rather go for this simpler approach tbh.
> I already do regular backups that are timestamped, it's enough for me 
> right now I think.

If you really think rolling your own deployment system is simpler than using
source control then I don't think you've understood all of the advantages of
source control. I know it can look complicated, but it's really not, and it
will make it far easier to keep track of what you're doing and what changes
are deployed where than the system you described. I strongly recommend you
reconsider.

-Stuart

--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/




Stuart,
If I may add to your post
 
Version control for different environments (Development and Production) is
SO key with SVN.
SVN has logging and other key features. 

Many, and when I say many that is an understatement, Many companies enforce
SVN for their protection.

Ever had a script not fully transfer, and only partial code remains?
With SVN you can roll it back and Whala! You have the original source back.

For one of my roles as Project Manager, I love Tortoise SVN. I have changed
the scripting a bit to send me emails with descriptions of changes as they
happen with attached files.
This way I can actually filter my emails to find the exact person who made
the bad change, what they had, and what they did instead of searching the
logs.

Since my developers can only push to the Development Servers I can fix
issues before they become a Production Issue.
No more, Developers having access to the server directly. They make their
changes and commit their changes up, I review and can schedule changes to be
committed to Production Servers.
To setup a new Developer I simply check out the SVN library for them and
they are up to speed day one.

The setup is very easy, Yes the controls are a tiny bit confusing at FIRST. 
But if you want success, then SVN is a SMART decision for any project.




Richard Buskirk














-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] code deployment through php

2012-05-01 Thread Stuart Dallas
On 1 May 2012, at 10:19, rene7705 wrote:

> On Tue, May 1, 2012 at 11:11 AM, Camilo Sperberg  wrote:
> 
>> If I understood the problem correctly, you want to keep a single copy of
>> your code on every machine you work, including the final server.
>> 
>> 
> Well, I want to work on 1 copy of my common code on my windows machine,
> then sync those changes to all my sites (hosted on the win dev box) to see
> if it messes up the other sites, then FTP those changes to my hosting
> account, and run the sync script there as well.
> 
> 
>> Have you read about SVN ? You can set up a cronjob to execute it
>> automatically if you want, there are clients for Windows, Zend Studio, etc
>> etc.
>> 
> 
> I've read about some source control systems, I've tried them out, but I'd
> rather go for this simpler approach tbh.
> I already do regular backups that are timestamped, it's enough for me right
> now I think.

If you really think rolling your own deployment system is simpler than using 
source control then I don't think you've understood all of the advantages of 
source control. I know it can look complicated, but it's really not, and it 
will make it far easier to keep track of what you're doing and what changes are 
deployed where than the system you described. I strongly recommend you 
reconsider.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

Re: [PHP] code deployment through php

2012-05-01 Thread rene7705
On Tue, May 1, 2012 at 11:11 AM, Camilo Sperberg  wrote:

> If I understood the problem correctly, you want to keep a single copy of
> your code on every machine you work, including the final server.
>
>
Well, I want to work on 1 copy of my common code on my windows machine,
then sync those changes to all my sites (hosted on the win dev box) to see
if it messes up the other sites, then FTP those changes to my hosting
account, and run the sync script there as well.


> Have you read about SVN ? You can set up a cronjob to execute it
> automatically if you want, there are clients for Windows, Zend Studio, etc
> etc.
>

I've read about some source control systems, I've tried them out, but I'd
rather go for this simpler approach tbh.
I already do regular backups that are timestamped, it's enough for me right
now I think.


Re: [PHP] code deployment through php

2012-05-01 Thread Camilo Sperberg

On 1 mei 2012, at 10:59, rene7705 wrote:

> Hi folks.
> 
> I was here a while ago, trying to figure out how to keep deployment
> instances of my common code, running on more than 1 site, in sync with
> eachother.
> 
> I've looked at rsync which was recommended here, but didn't like it much,
> nor could I find a good windows version of it.
> 
> So yesterday, I decided to try a pure PHP solution. My thinking was: run a
> PHP sync script once on each physical machine that holds possibly multiple
> copies of my common code, and FTP the common code only 1 time because I use
> only 1 shared hosting account besides my windows development machine.
> 
> I've gotten it so far that it creates an imo good list of what to copy
> where.
> 
> The only problem I can foresee is that the copy command will take more than
> 30 seconds, which makes it hard to run at the shared hoster.
> 
> And obviously, it's going to need some good input checking to prevent
> abuse.
> 
> I've put up a demo at
> http://skatescene.biz/sites/mediabeez.ws/sync_secret_cndj593n2/ , you can
> "execute" the "code" job to see it in action.
> 
> I'll also post the working copy of my sync library at the bottom of this
> post. The only thing missing is the actual copy($source,$dest), I think.
> 
> But, I'm wondering if this is a good approach to code deployment. It
> certainly seems easier and more convenient to me than using rsync. Maybe
> i'm an amateur indeed ;)  Anyways, all criticism is welcome here. Thanks
> for your time! :)
> 
>  function sync_echo_jobs ($path) {
> $jobs = sync_read_jobs ($path);
> echo '';
> echo '';
> foreach ($jobs['jobs'] as $jobName => $job) {
> echo ''.$jobName.' ( href="javascript:rscg.executeJob(\''.$jobName.'\');">execute) ( href="javascript:rscg.showEditJobForm(\''.$jobName.'\');">edit)';
> }
> echo '';
> ?>
>  }
> 
> function sync_read_jobs ($path) {
> $filepath = $path.'/rajmvSync_jobs.json';
> if (file_exists($filepath)) {
> $r = json_decode (file_get_contents($filepath), true);
> } else {
> $r = array (
> 'jobs' => array()
> );
> }
> return $r;
> }
> 
> function sync_write_jobs ($path, $jobs) {
> $filepath = $path.'/rajmvSync_jobs.json';
> file_put_contents ($filepath, json_encode($jobs));
> }
> 
> function sync_addOrEditJob ($path, $name, $paths) {
> $jobs = sync_read_jobs ($path);
> $jobs['jobs'][$name] = array (
> 'paths' => $paths
> );
> sync_write_jobs ($path, $jobs);
> }
> 
> function sync_executeJob ($path, $name) {
> $jobs = sync_read_jobs ($path);
> if (array_key_exists($name, $jobs['jobs'])) {
> $job = $jobs['jobs'][$name];
> $paths = explode ("\n", $job['paths']);
> // work only on approved paths;
> $pathsApproved = array();
> foreach ($paths as $idx=>$pathToSync) {
> $drive = strtolower(substr($pathToSync,0,2));
> if ($drive=='m:') $pathsApproved[]=$pathToSync;
> }
> $paths = $pathsApproved;
> 
> // get a list of files for each path to sync with the other paths in the
> same list/var
> $fileLists = array();
> foreach ($paths as $idx => $pathToSync) {
> $fileLists[$pathToSync] = getFilePathList ($pathToSync, true, "/(.*)/",
> array('file'));
> }
> // get all the last modified timestamps for each of the found files
> $fileList = array();
> foreach ($paths as $idx => $pathToSync) {
> foreach ($fileLists[$pathToSync] as $idx2 => $filepathToSync) {
> $fileRelativePath = str_replace ($pathToSync, '', $filepathToSync);
> if (!array_key_exists($fileRelativePath, $fileList))
> $fileList[$fileRelativePath] = array();
> $fileList[$fileRelativePath][$pathToSync] = filemtime($filepathToSync);
> }
> }
> // $copyList will hold all the copy commands, initialize;
> $copyList = array();
> foreach ($fileList as $fileRelativePath => $locationResults) {
> foreach ($locationResults as $pathToSync => $filemtime) {
> if (!array_key_exists($fileRelativePath, $copyList))
> $copyList[$fileRelativePath] = array(
> 'latest' => null,
> 'source' => null,
> 'destinations' => array()
> );
> if (is_null($copyList[$fileRelativePath]['latest']) || $filemtime >
> $copyList[$fileRelativePath]['latest']) {
> $copyList[$fileRelativePath]['source'] = $pathToSync;
> $copyList[$fileRelativePath]['latest'] = $filemtime;
> }
> }
> }
> 
> // schedule copy command for all files with older filemtime() than the
> latest copy
> foreach ($fileList as $fileRelativePath => $locationResults) {
> foreach ($locationResults as $pathToSync => $filemtime) {
> if ($filemtime < $copyList[$fileRelativePath]['latest']) {
> $copyList[$fileRelativePath]['destinations'][] = $pathToSync;
> }
> }
> }
> // schedule copy command for all new files that must go to all $pathToSync
> where it is not present yet:
> foreach ($copyList as $fileRelativePath => $fileRec) {
> if (count($fileList[$fileRelativePath])!=count($paths)) {
> foreach ($paths as $idx=>$pathToSync) {
> if (!array_key_exists($pathToSync, $fileList[$fileRelativePath]))
> $copyList[$fileRelativePath]['destinations'][] = $pathToSync;
> }
> }
> }
> 
> // debug output of actual copy commands
> foreach ($copyList a