Skip to content

Instantly share code, notes, and snippets.

@adamjakab
Last active August 29, 2015 14:07
Show Gist options
  • Save adamjakab/4f46923f888cbff1f030 to your computer and use it in GitHub Desktop.
Save adamjakab/4f46923f888cbff1f030 to your computer and use it in GitHub Desktop.
PHP script to test chrooted environment - mainly: session, network, mail
<?php
/*
* Test PHP IN CHROOT
*/
$remoteUrl = "http://www.cyberciti.biz/files/lighttpd/l2chroot.txt";
$testMail = "yourmail@yourdomain.com";
$testHostname = "google.com";
ini_set("display_errors", 1);
//start a session - you could have wrong session.save_path or other
session_start();
//test name resolution
echo "Host($testHostname) resoles to ip: " . gethostbyname( $testHostname );
echo "<hr />";
//test file_get_contents with remote content fopen
$homepage = file_get_contents($remoteUrl);
echo 'REMOTE CONTENT(FOPEN): <pre>' . $homepage . '</pre>';
echo "<hr />";
//test curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $remoteUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
echo 'REMOTE CONTENT(CURL): <pre>' . $output . '</pre>';
echo "<hr />";
//test date(did you copy usr/share/zoneinfo?)
print_r( getdate() );
echo "<hr />";
//test sending mails - it's too much hassle - use smtp
$res = mail( $testMail, "testing123", "ciao!" );
echo "Your mail has been sent? " . ($res?"YES":"NO");
//
//phpinfo();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment