Skip to content

Commit

Permalink
restart php daemon when not responding
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadam committed Mar 26, 2024
1 parent 10fb1f5 commit 8f87a08
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions t/lib/MT/Test/Tag.pm
Original file line number Diff line number Diff line change
Expand Up @@ -319,28 +319,36 @@ my $PHP_DAEMON;
sub MT::Test::Tag::_php_daemon {
my ($template, $blog_id, $extra, $text, $log) = @_;

$PHP_DAEMON ||= Test::TCP->new(
code => sub {
my $port = shift;
my $command = MT::Test::PHP::_make_php_command();
my $config = MT->instance->find_config;
my @opts = (
$ENV{MT_HOME} . '/t/lib/MT/Test/Tag/daemon.php',
'--port', $port,
'--mt_home', ($ENV{MT_HOME} ? $ENV{MT_HOME} : '.'),
'--mt_config', $config,
'--init_blog_id', $blog_id,
'--ignore_php_dynamic_properties_warnings', ($ENV{MT_TEST_IGNORE_PHP_DYNAMIC_PROPERTIES_WARNINGS} || 0),
$log ? ('--log', $log) : (),
);
exec join(' ', @$command, @opts);
});

socket(my $sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "Cannot create socket: $!";
my $port = $PHP_DAEMON->port;
my $packed_remote_host = inet_aton('127.0.0.1');
my $sock_addr = sockaddr_in($port, $packed_remote_host);
connect($sock, $sock_addr) or die "Cannot connect to 127.0.0.1:$port: $!";
my $sock;
for my $retry_current (1..3) {
$PHP_DAEMON ||= Test::TCP->new(
code => sub {
my $port = shift;
my $command = MT::Test::PHP::_make_php_command();
my $config = MT->instance->find_config;
my @opts = (
$ENV{MT_HOME} . '/t/lib/MT/Test/Tag/daemon.php',
'--port', $port,
'--mt_home', ($ENV{MT_HOME} ? $ENV{MT_HOME} : '.'),
'--mt_config', $config,
'--init_blog_id', $blog_id,
'--ignore_php_dynamic_properties_warnings', ($ENV{MT_TEST_IGNORE_PHP_DYNAMIC_PROPERTIES_WARNINGS} || 0),
$log ? ('--log', $log) : (),
);
exec join(' ', @$command, @opts);
});

socket($sock, PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die "Cannot create socket: $!";
my $port = $PHP_DAEMON->port;
my $packed_remote_host = inet_aton('127.0.0.1');
my $sock_addr = sockaddr_in($port, $packed_remote_host);
unless (connect($sock, $sock_addr)) {
$PHP_DAEMON = undef;
note "Cannot connect to 127.0.0.1:$port Retrying";
next;
}
die "Cannot connect to 127.0.0.1:$port: $!" unless $PHP_DAEMON && $sock;
}

if ($text) {
$extra =<<"PHP" . $extra;
Expand Down

0 comments on commit 8f87a08

Please sign in to comment.