tags:

views:

373

answers:

4

HipHop compiles PHP in a C executable. What happens with PHP errors ?

Is that harder to debug ?

edit : I looked through the documentation but didn't find anything

+6  A: 

I did a couple of quick tests (haven't have the time to play with hiphop as much as I'd like, unfortunately ;-( ) ; here are the results I got :



First of all, here's the content of test-2.php, which contains a parse error :

<?php

echo "what with a parse error ?

Note : the string is not finished


Trying to run that with PHP, I get :

$ php test-2.php 
PHP Parse error:  syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /home/squale/temp/hiphop-php/tests/test-2.php on line 5

Parse error: syntax error, unexpected $end, expecting T_VARIABLE or T_DOLLAR_OPEN_CURLY_BRACES or T_CURLY_OPEN in /home/squale/temp/hiphop-php/tests/test-2.php on line 5


Trying to compile that with hiphop, I get :

$ /home/squale/temp/hiphop-php/hiphop-php/src/hphp/hphp test-2.php --keep-tempdir=1 --log=3
running hphp...
creating temporary directory /tmp/hphp_JdsWcU ...
parsing inputs...
parsing ./test-2.php...
parsing inputs took 0'00" (0 ms) wall time
running hphp took 0'00" (154 ms) wall time
Exception: Unable to parse file: ./test-2.php
 (Line: 5, Char: 0): syntax error, unexpected $end

i.e. the file with the parse error doesn't compile -- which stands to reason.

The error message has some informations that were present in the PHP's error message -- but not exactly as precise...

Which means you might want to try with PHP before trying to compile your application with hiphop : the error message given by PHP was more descriptive.



Now, let's try with some runtime errors/warnings ; here's the content of test-1.php :

<?php                                                                                                                                                                                                                                                                          

error_reporting(E_ALL);                                                                                                                                                                                                                                                        
ini_set('display_errors', 'On');                                                                                                                                                                                                                                               

if ($_GET['test'] == '1') {                                                                                                                                                                                                                                                    
        $data = (object)array(10);                                                                                                                                                                                                                                             
        echo $data[0];                                                                                                                                                                                                                                                         
} else if ($_GET['test'] == '2') {                                                                                                                                                                                                                                             
        echo 10/0;                                                                                                                                                                                                                                                             
} else if ($_GET['test'] == '3') {                                                                                                                                                                                                                                             
        file_put_contents('/bin/non-allowed', 'hello !');                                                                                                                                                                                                                      
}

echo "plop\n";

Trying to run that file from Apache+PHP, you'd get three possible errors :
(I copied the file to my document root -- which means the paths will not be the same for the errors with Apache)

First of all, calling http://localhost/temp/test-1.php?test=1 I get :

Fatal error: Cannot use object of type stdClass as array in /home/squale/developpement/tests/temp/test-1.php on line 8

And, trying http://localhost/temp/test-1.php?test=2 I get :

Warning: Division by zero in /home/squale/developpement/tests/temp/test-1.php on line 10
plop 

And, finally, with http://localhost/temp/test-1.php?test=3, I get :

Warning: file_put_contents(/bin/non-allowed) [function.file-put-contents]: failed to open stream: Permission denied in /home/squale/developpement/tests/temp/test-1.php on line 12
plop


Now, compiling that test-1.php file with hiphop and running it in web-server mode, I get this during the compilation phase, which means it is OK :

$ /home/squale/temp/hiphop-php/hiphop-php/src/hphp/hphp test-1.php --keep-tempdir=1 --log=3
running hphp...
creating temporary directory /tmp/hphp_xXZ8US ...
parsing inputs...
parsing ./test-1.php...
parsing inputs took 0'00" (1 ms) wall time
pre-optimizing...
pre-optimizing took 0'00" (0 ms) wall time
inferring types...
inferring types took 0'00" (0 ms) wall time
post-optimizing...
post-optimizing took 0'00" (0 ms) wall time
creating CPP files...
creating CPP files took 0'00" (32 ms) wall time
compiling and linking CPP files...

compiling and linking CPP files took 0'39" (39807 ms) wall time
running executable /tmp/hphp_xXZ8US/program --file test-1.php...
plop
all files saved in /tmp/hphp_xXZ8US ...
running hphp took 0'40" (40054 ms) wall time

And, then, launching the server :

$ /tmp/hphp_xXZ8US/program -m server -p 8080
Could not mlockall
loading static content...
loading static content took 0'00" (0 ms) wall time
page server started
admin server started
all servers started


Now, let's try accessing those three URLs ; first, calling http://localhost:8080/test-1.php?test=1 I get :

  • Nothing in the browser
  • Unhandled error: Invalid operand type was used: not ArrayAccess objects. in the console from which I started the server

For http://localhost:8080/test-1.php?test=2, I get :

  • In the browser : plop
  • In the console from which I started the browser : Division by zero

And, finally, for http://localhost:8080/test-1.php?test=3, I get :

  • In the browser : plop
  • In the console : nothing

Here, too, indications of errors are not quite as good as with PHP... at least with default options...



Judging from hiphop's Runtime options wiki page, you can specify a config file that contains some options.
Here's the content of the config.txt I used :

Log {
    Level = Verbose
    NoSilencer = true
    AlwaysLogUnhandledExceptions = true
    RuntimeErrorReportingLevel = 6143
    Header = false
    InjectedStackTrace = true
    NativeStackTrace = true
    MaxMessagesPerRequest = -1
}

ErrorHandling {
    CallUserHandlerOnFatals = true
    NoInfiniteLoopDetection = false
    NoInfiniteRecursionDetection = false
    MaxStackDepth = 1000
    ThrowBadTypeExceptions = true
    ThrowNotices = true
    NoticeFrequency = 1    # 1 out of these many notices to log
    WarningFrequency = 1   # 1 out of these many warnings to log
    AssertActive = false
    AssertWarning = false
  }


Re-starting the server, using the --config switch to point to that file :

$ /tmp/hphp_xXZ8US/program -m server -p 8080 --config=config.txt
Could not mlockall
loading static content...
loading static content took 0'00" (0 ms) wall time
page server started
admin server started
all servers started

I should get more informations... let's try our three requests again.


First, calling http://localhost:8080/test-1.php?test=1 I get :

  • Same as before

For http://localhost:8080/test-1.php?test=2, I get :

  • Same as before

And, finally, for http://localhost:8080/test-1.php?test=3, I get :

  • In the browser : plop
  • In the console : a new error message that I didn't get before : f_file_put_contents/316: Permission denied


I didn't try much more, but playing with that config file and the --config switch looks like an interesting idea ;-)



Note : I did those tests on Ubuntu 9.10 64bits -- which is an officially supported system ; installation was quite easy.

Which means you could try those, doing an install in a Virtual Machine, for example : as long as you know a bit about Linux and compiling software, installing hiphop is not an impossible task.

Pascal MARTIN
This is an awesome answer !! Thank you, great job
Matthieu
You're welcome :-) *(I had been planning to compile hiphop for quite some time... now that it's done, and I had fun with the first steps, I'll be able to have some more fun testing it a bit more ^^ )*
Pascal MARTIN
A: 

i have install finish hiphop in linux x64. and i run one file cuongnv.php is ok . but i can't run file hello.php ? what happens with hiphop

nguyen van cuong
A: 

i have been run it ok. thank you

nguyen van cuong
A: 

I havent found any doc on help debugging a failed compilation. In my case no errors were shown but only the "HPHP Failed"

Purefan