jamal13579
August 2nd, 2015, 01:18 PM
I am sure that this is on the dumb end of the spectrum but I have been trawling the internet for hours and I can't get it to work (I really need to brush up (read: do the 101) on regex! Any help from you guys very much appreciated.
I am trying to migrate the following shell command to PHP:
curl -s "http://localhost:80/balancer-manager" | grep "http"
This returns 5 lines:
<td><a href="/balancer-manager?b=localhost_cluster1&w=http://localhost:8080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8080</a></td><td>69be0093449f0252bebabf73014df23f_server1_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>74</td><td> 40K</td><td> 15K</td></tr>
<td><a href="/balancer-manager?b=localhost_cluster2&w=http://localhost:8180&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8180</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_cluster00&w=http://localhost:7080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:7080</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_singleton1&w=http://localhost:8080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8080</a></td><td></td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_singleton2&w=http://localhost:8180&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8180</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
I then strip this and do some stuff with it. At the moment I am calling shell_exec to perform this but I want to migrate it all over to PHP. This is what I have at the moment but it doesn't work:
$url = "$protocol://$host:$port/balancer-manager";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_match('/http/g', $result);
print_r($result);
Any help very much appreciated.
Chris
I am trying to migrate the following shell command to PHP:
curl -s "http://localhost:80/balancer-manager" | grep "http"
This returns 5 lines:
<td><a href="/balancer-manager?b=localhost_cluster1&w=http://localhost:8080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8080</a></td><td>69be0093449f0252bebabf73014df23f_server1_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>74</td><td> 40K</td><td> 15K</td></tr>
<td><a href="/balancer-manager?b=localhost_cluster2&w=http://localhost:8180&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8180</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_cluster00&w=http://localhost:7080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:7080</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_singleton1&w=http://localhost:8080&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8080</a></td><td></td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
<td><a href="/balancer-manager?b=localhost_singleton2&w=http://localhost:8180&nonce=3abe47c9-f724-4fdb-9e9c-0c91aa3e1f92">http://localhost:8180</a></td><td>69be0093449f0252bebabf73014df23f_server2_1</td><td></td><td>1</td><td>0</td><td>Ok</td><td>0</td><td> 0 </td><td> 0 </td></tr>
I then strip this and do some stuff with it. At the moment I am calling shell_exec to perform this but I want to migrate it all over to PHP. This is what I have at the moment but it doesn't work:
$url = "$protocol://$host:$port/balancer-manager";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = preg_match('/http/g', $result);
print_r($result);
Any help very much appreciated.
Chris