Execute PHP from GIT post-update hook - php

I am using GIT on my server and I am trying to get a PHP file to be executed each time I update my repository. I'm trying to use my post-update hook to achieve this.
this is the code I tried:
#!/bin/sh
echo
echo "**** Pulling changes into Prime [Hub's post-update hook]"
echo
cd $HOME/www || exit
unset GIT_DIR
git pull hub master
exec git-update-server-info
php /path/to/directory/file.php
I can't seem to get the PHP to execute. Anyone able to shine any light on this?

exec never returns. Anything you put after the exec call is dead code.
Remove the exec, or place it before your php line if that's the last thing that needs to be done. (And after doing error checking if necessary obviously.)
So for instance
...
git-update-server-info
exec php /path/to/directory/file.php
Or just simply
...
git-update-server-info
php /path/to/directory/file.php
(or move the statements around if your php script can be called before the git command.)

Related

abort build on php warnings/errors

We have several php scripts wrapped with other non-php commands in a single shell script, like this:
build_stuff.sh
mv things stuff
cp files folders
composer install
php bin/console some:command
php bin/console some:other:command
This shell script is then called in a "execute shell" build step.
sh ./build_stuff.sh
Is there any possibility to abort the build as "failure", as soon as there are php errors/warnings?
So that the next command wouldn't be executed.
And still maintain all commands in one script.
...
I found the Log Parser Plugin, but i would like to abort when the errors occur, not continue and parse the logs afterwards.
I though about maybe catching the PHP exit codes, as described here:
Retrieve exit status from php script inside of shell script
But you wouldn't be able to instantly see text output of the php scripts then, would you?
Combining them with double ampersands will do the job. In the below example cmd2 will be executed only if cmd1 succeeds (returns a zero exit status).
cmd1 && cmd2
It will work with composer; but your commands might need modification to send proper exit codes.

Is it possible to programmatically launch the php interactive shell from a file?

I would like to be able to either launch php in interactive mode via phing or via PHP (worst case scenario, phing can run an adhoc task with the desired code).
I've gotten this far:
<?php
$cmd = 'php -d auto_prepend_file=bootstrap.php -a';
passthru($cmd)
And the above almost gets me what I want. I enter a shell I can interact with, but the prompts are gone (the php > at the start of each line), all meta-commands (e.g., \>) totally fail, and typing exit; does nothing instead of exit the shell. So, as you can see, this isn't the ideal shell. Is this even possible without installing phpsh?
Thanks in advance.
I think PsySH will give you want you want. It's a PHP REPL that gives you the option to configure it to automatically include a bootstrap file.

Run javascript function from cmd

Hi i was trying to emulate a post created from javascript in a site with curl from a php script but it seems some variables have the same name and they get overwritten, is there a way to run the script itself from command promt, assuming i make the necessary changes to it?
Well ... you can always install NodeJS and then just write in terminal: node <filename>

Using PHP to run ANT Build.xml file on Server

I'm trying to run a Ant build.xml file via a cronjob. I have seen that i can run system commands with php and wondered whether these could be used to run the ant build file? If so i can then setup a cron job to run the php file every night?
Does anyone know whether this is possible?
For instance i have the following in my php file:
system("ant ./build/cronjob/build.xml");
Although this produces output it doesn't appear to be working?
Has anyone else come across this?
First step is to ensure you can run ant ./build/cronjob/build.xml from command prompt. Creating cron entry will be then straight forward.
I prefer creating a wrapper script, say $HOME/scripts/callant.sh. The script could be like
#!bash
#setup variables
BUILD_FILE=/build/cronjob/build.xml
ANT_CMD=/pathtoant/bin/ant
JAVA_HOME=<path to jdk>
#setup path
#setp LD_LIBRARY_PATH ..
$ANT_CMD -f $BUILD_FILE > /tmp/$$out.log 2>/tmp/$$err.log

Using PHP to write git hooks

I want to use PHP writing git hooks but have some problem.
I use Windows 7 LAMP packet and git bash.
So, if I run the next script (pre-commit hook) through git shell:
https://gist.github.com/713716
it works fine and there is 123 on the screen. But if I use:
git commit
I have the next error:
error: cannot spawn .git/hooks/pre-commit: No such file or directory
So, what the problem is?
I rarely work on Windows systems but it might have something to do with either making sure the pre-commit file is executable by every user (per Phil's comment), or something to do with git invoking a php command.
Looks like this problem may exist elsewhere but not easily reproduceable.
It's janky, but it might work if you create a new file somewhere with a php extension and invoke that file from the pre-commit hook.
#pre-commit
C:/WebServers/usr/local/php5/php C:/path/to/123.php
#123.php
<?php echo 123 ?>

Categories