I have modified a version of this github project https://github.com/lkwdwrd/git-deploy [I modified it as for some reason JSON wasnt being parsed on my server (Mediatemple Grid Server) & I also added custom logging] The script autodeploys github repos using git hooks.
The script was working fine for a while but recently stopped working.
I've isolated the problem to the git fetch command. This the exact code I'm using:
exec( 'git fetch ' . $this->_remote . ' ' . $this->_branch, $fetch_output, $fetch_return_var );
The $fetch_output array is blank and the $fetch_return_var is 255. So I believe that the 255 really means -1, which is an error with the git command.
However I am able to successfully execute this command when SSH'd into the server and running as the same user with the exact same string as is being build as the 1st argument of the exec() function.
So now I'm lost.
thanks in advance
UPDATE:
Thanks to @Matthias Huttar I changed my exec() to a proc_open() call that allowed me to see the output of STDERR [not sure why it was not logging thru exec() but I think it is because it was a subprocess of git fetch]. This output is:
error: cannot fork() for git-remote-https: Resource temporarily unavailable
So I think there is an issue with my server environment. However I'm still not certain.
if there is an error in you git fetch then the output will very likely not be written to stdout but to stderr. exec will only give you the output of stdout and ignore stderr.
exec( 'git fetch ' . $this->_remote . ' ' . $this->_branch.' 2>&1', $fetch_output, $fetch_return_var );
will very likely show your error. my suspicion is that the git process you invoke from php runs as a different user (e.g. you apache server's user) and therefore does nit have access to you ssh key (or username/password). If that is the case your error msg will be something with "permission denied". the solution would be o generate a new default ssh key for that user and grant this key access in github ("deploy key" is how github calls this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With