3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/env php <?php mail('kaka001@mailinator.com','running index', 'running'); require dirname(__FILE__).'/goutte.phar'; // Last id $last_id = get_last_id(); $is_running = get_running(); if($is_running == 1) { print 'Another cron is running: '.$is_running; exit; } $server = array( 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13', ); is_running(1); // Number download per request $count = 30; $current_id = $last_id; for($i = 0; $i <= $count; $i++) { $current_id -=1; $client = new Goutte\Client($server); $url = 'http://comment.dantri.com.vn/ListReplyCommentAjax.aspx?PageIndex=1&PageSize=2000&NewsId='.$current_id; $crawler = $client->request('GET', $url); print $url."\n"; $output = ''; $crawler->filter('div.item .middle')->each(function (Symfony\Component\DomCrawler\Crawler $node, $i) use ($current_id) { $name = $node->filter('.name .text')->text(); $date = $node->filter('.name .date')->text(); $email = $node->filter('.email')->text(); $name = mb_convert_case(str_replace(array('(', ')', '"'), '', $name), MB_CASE_TITLE, "UTF-8"); $date = str_replace(array('(', ')', '"'), '', $date); $email = strtolower($email); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $output = '"'.$current_id.'","'.$name.'","'.$email.'","'.$date.'"'."\n"; cache_output($output); } }); $output = cache_output(); print $output; if(!empty($output)) { save_csv($output); } } save_last_id($current_id); is_running(0); function cache_output($string = '') { static $output = ''; $output .= $string; return $output; } function save_csv($row) { $path = dirname(__FILE__).'/'.date('Y-m-d') . '.csv'; $fh = fopen($path, "a+"); if ($fh) { fwrite($fh, $row); } else { print 'Can not write file'; return FALSE; } fclose($fh); } function save_last_id($id) { $filename = dirname(__FILE__).'/last_id.txt'; $path = $filename; $fh = @fopen($path, "w+"); if ($fh) { @fwrite($fh, $id); } else { print 'Can not write file'; return FALSE; } @fclose($fh); } function get_last_id() { $path = dirname(__FILE__).'/last_id.txt'; $fh = @fopen($path, "r"); if ($fh) { $id = @fgets($fh); @fclose($fh); return $id; } else { print 'Can not open file'; return FALSE; } } function is_running($status = FALSE) { $path = dirname(__FILE__).'/running.txt'; $fh = @fopen($path, "w+"); if ($fh) { @fwrite($fh, $status); } else { print 'Can not write file'; return FALSE; } @fclose($fh); } function get_running() { $path = dirname(__FILE__).'/running.txt'; $fh = fopen($path, "r"); if ($fh) { $id = fgets($fh); @fclose($fh); return $id; } else { print 'Can not open file'; return FALSE; } }
Output for 8.0.14 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Call to undefined function mail() in /in/ghbhp:3 Stack trace: #0 {main} thrown in /in/ghbhp on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.13
Warning: mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i' in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): Failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: Uncaught Error: Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp:5 Stack trace: #0 {main} thrown in /in/ghbhp on line 5
Process exited with code 255.
Output for 7.4.27 - 7.4.33
Warning: mail() has been disabled for security reasons in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: require(): Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp on line 5
Process exited with code 255.
Output for 7.3.19 - 7.3.33, 7.4.7 - 7.4.26
Warning: mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i' in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: require(): Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp on line 5
Process exited with code 255.
Output for 5.3.10, 5.6.31 - 5.6.40, 7.0.32 - 7.0.33, 7.1.22 - 7.1.33, 7.2.10 - 7.2.34, 7.3.0 - 7.3.18, 7.4.0 - 7.4.6
Warning: mail(): Could not execute mail delivery program ' -t -i ' in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: require(): Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp on line 5
Process exited with code 255.
Output for 5.3.0 - 5.3.9, 5.3.11 - 5.3.24, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.31, 7.1.0 - 7.1.21, 7.2.0 - 7.2.9
Warning: mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i ' in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: require(): Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp on line 5
Process exited with code 255.
Output for 5.3.25 - 5.3.29
Warning: mail(): Could not execute mail delivery program '/usr/bin/sendmail -t -i ' in /in/ghbhp on line 3 Warning: require(/in/goutte.phar): failed to open stream: No such file or directory in /in/ghbhp on line 5 Fatal error: require(): Failed opening required '/in/goutte.phar' (include_path='.:') in /in/ghbhp on line 5
Process exited with code 255.
Output for 5.2.3 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/ghbhp on line 27 Parse error: syntax error, unexpected T_STRING in /in/ghbhp on line 27
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/ghbhp</b> on line <b>27</b><br /> <br /> <b>Parse error</b>: syntax error, unexpected T_STRING in <b>/in/ghbhp</b> on line <b>27</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/ghbhp</b> on line <b>27</b><br /> <br /> <b>Parse error</b>: parse error, unexpected T_STRING in <b>/in/ghbhp</b> on line <b>27</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Warning</b>: Unexpected character in input: '\' (ASCII=92) state=1 in <b>/in/ghbhp</b> on line <b>27</b><br /> <br /> <b>Parse error</b>: parse error in <b>/in/ghbhp</b> on line <b>27</b><br />
Process exited with code 255.

preferences:
337.87 ms | 402 KiB | 468 Q