Fix header_matching for PHP and Ruby (#26017)

diff --git a/src/php/tests/interop/xds_client.php b/src/php/tests/interop/xds_client.php
index 3990c21..b814652 100644
--- a/src/php/tests/interop/xds_client.php
+++ b/src/php/tests/interop/xds_client.php
@@ -386,10 +386,14 @@
                 // $this->metadata_to_send[$rpc] somehow becomes a
                 // Volatile object, instead of an associative array.
                 $metadata_array = [];
+                $execute_in_child_process = false;
                 foreach ($metadata as $key => $value) {
                     $metadata_array[$key] = [$value];
+                    if ($key == 'rpc-behavior' || $key == 'fi_testcase') {
+                        $execute_in_child_process = true;
+                    }
                 }
-                if ($metadata_array && $this->rpc_config->tmp_file1) {
+                if ($execute_in_child_process && $this->rpc_config->tmp_file1) {
                     // if 'rpc-behavior' is set, we need to pawn off
                     // the execution to some other child PHP processes
                     $this->execute_rpc_in_child_process(
diff --git a/src/ruby/pb/test/xds_client.rb b/src/ruby/pb/test/xds_client.rb
index 2eab7b5..ed111b0 100755
--- a/src/ruby/pb/test/xds_client.rb
+++ b/src/ruby/pb/test/xds_client.rb
@@ -283,7 +283,7 @@
         raise "Unsupported rpc #{rpc}"
       end
       rpc_stats_key = rpc.to_s
-      if not metadata.empty?
+      if metadata.key?('rpc-behavior') or metadata.key?('fi_testcase')
         keep_open_threads << execute_rpc_in_thread(op, rpc_stats_key)
       else
         results[rpc] = execute_rpc(op, fail_on_failed_rpcs, rpc_stats_key)