3v4l.org

run code in 300+ PHP versions simultaneously
<?php // API access key from Google API's Console define( 'API_ACCESS_KEY', 'AIzaSyBNVpyGHobo0YbdyOejbL7ixMES9iwV6VA' ); $registrationIds = array("APA91bHgZ3qu3-VeJ0RC0J9EyB33qX5jB4pX1qEiZtdEiYSJoF8gYA67AeL0j4g7z6sNwLHg1kIQ__p5foZhWnXBybhcEZjp650DzUZXqQBf_fZnWc8xqVIMQMUrdHOtzYDX7DsyL7fyFFoUsF9pElZh8AYftELjlGbJqs-mGZSYg6zBVgXjhq0"); // prep the bundle $msg = array ( 'message' => 'Hello Prem here. Did you get this. message', 'title' => 'This is a title. title', 'subtitle' => 'This is a subtitle. subtitle', 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here', 'vibrate' => 1, 'sound' => 1 ); $fields = array ( 'registration_ids' => $registrationIds, 'data' => $msg ); $headers = array ( 'Authorization: key=' . API_ACCESS_KEY//, //'Content-Type: application/json' ); // Submit those variables to the server $post_data = array( 'test' => 'foobar', 'okay' => 'yes', 'number' => 2 ); // Send a request to example.com $result = post_request('https://android.googleapis.com/gcm/send', $fields, $headers); //$ch = curl_init(); //curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' ); //curl_setopt( $ch,CURLOPT_POST, true ); //curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); //curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); //curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); //curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); //$result = curl_exec($ch ); //curl_close( $ch ); echo $result; function post_request($url, $data, $headers, $referer='') { // Convert the data array into URL Parameters like a=b&foo=bar etc. $data = http_build_query($data); // parse the given URL $url = parse_url($url); if ($url['scheme'] != 'http') { die('Error: Only HTTP request are supported !'); } // extract host and path: $host = $url['host']; $path = $url['path']; // open a socket connection on port 80 - timeout: 30 sec $fp = fsockopen($host, 80, $errno, $errstr, 30); if ($fp){ // send the request headers: fputs($fp, "POST $path HTTP/1.1\r\n"); fputs($fp, "Host: $host\r\n"); if ($referer != '') fputs($fp, "Referer: $referer\r\n"); fputs($fp, $headers); fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); fputs($fp, "Content-length: ". strlen($data) ."\r\n"); fputs($fp, "Connection: close\r\n\r\n"); fputs($fp, $data); $result = ''; while(!feof($fp)) { // receive the results of the request $result .= fgets($fp, 128); } } else { return array( 'status' => 'err', 'error' => "$errstr ($errno)" ); } // close the socket connection: fclose($fp); // split the result header from the content $result = explode("\r\n\r\n", $result, 2); $header = isset($result[0]) ? $result[0] : ''; $content = isset($result[1]) ? $result[1] : ''; // return as structured array: return array( 'status' => 'ok', 'header' => $header, 'content' => $content ); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gIsag
function name:  (null)
number of ops:  22
compiled vars:  !0 = $registrationIds, !1 = $msg, !2 = $fields, !3 = $headers, !4 = $post_data, !5 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'API_ACCESS_KEY'
          2        SEND_VAL                                                 'AIzaSyBNVpyGHobo0YbdyOejbL7ixMES9iwV6VA'
          3        DO_ICALL                                                 
    8     4        ASSIGN                                                   !0, <array>
   11     5        ASSIGN                                                   !1, <array>
   23     6        INIT_ARRAY                                       ~9      !0, 'registration_ids'
   24     7        ADD_ARRAY_ELEMENT                                ~9      !1, 'data'
   21     8        ASSIGN                                                   !2, ~9
   29     9        FETCH_CONSTANT                                   ~11     'API_ACCESS_KEY'
         10        CONCAT                                           ~12     'Authorization%3A+key%3D', ~11
         11        INIT_ARRAY                                       ~13     ~12
   27    12        ASSIGN                                                   !3, ~13
   34    13        ASSIGN                                                   !4, <array>
   41    14        INIT_FCALL_BY_NAME                                       'post_request'
         15        SEND_VAL_EX                                              'https%3A%2F%2Fandroid.googleapis.com%2Fgcm%2Fsend'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !3
         18        DO_FCALL                                      0  $16     
         19        ASSIGN                                                   !5, $16
   53    20        ECHO                                                     !5
  126    21      > RETURN                                                   1

Function post_request:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 88
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 52
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 77
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 95
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 106, Position 2 = 109
Branch analysis from position: 106
1 jumps found. (Code = 42) Position 1 = 110
Branch analysis from position: 110
2 jumps found. (Code = 43) Position 1 = 113, Position 2 = 116
Branch analysis from position: 113
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 116
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 113, Position 2 = 116
Branch analysis from position: 113
Branch analysis from position: 116
Branch analysis from position: 77
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 77
Branch analysis from position: 87
Branch analysis from position: 77
Branch analysis from position: 52
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gIsag
function name:  post_request
number of ops:  123
compiled vars:  !0 = $url, !1 = $data, !2 = $headers, !3 = $referer, !4 = $host, !5 = $path, !6 = $fp, !7 = $errno, !8 = $errstr, !9 = $result, !10 = $header, !11 = $content
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      ''
   62     4        INIT_FCALL                                               'http_build_query'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $12     
          7        ASSIGN                                                   !1, $12
   65     8        INIT_FCALL                                               'parse_url'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $14     
         11        ASSIGN                                                   !0, $14
   67    12        FETCH_DIM_R                                      ~16     !0, 'scheme'
         13        IS_NOT_EQUAL                                             ~16, 'http'
         14      > JMPZ                                                     ~17, ->16
   68    15    > > EXIT                                                     'Error%3A+Only+HTTP+request+are+supported+%21'
   72    16    >   FETCH_DIM_R                                      ~18     !0, 'host'
         17        ASSIGN                                                   !4, ~18
   73    18        FETCH_DIM_R                                      ~20     !0, 'path'
         19        ASSIGN                                                   !5, ~20
   76    20        INIT_FCALL                                               'fsockopen'
         21        SEND_VAR                                                 !4
         22        SEND_VAL                                                 80
         23        SEND_REF                                                 !7
         24        SEND_REF                                                 !8
         25        SEND_VAL                                                 30
         26        DO_ICALL                                         $22     
         27        ASSIGN                                                   !6, $22
   78    28      > JMPZ                                                     !6, ->88
   81    29    >   INIT_FCALL                                               'fputs'
         30        SEND_VAR                                                 !6
         31        ROPE_INIT                                     3  ~25     'POST+'
         32        ROPE_ADD                                      1  ~25     ~25, !5
         33        ROPE_END                                      2  ~24     ~25, '+HTTP%2F1.1%0D%0A'
         34        SEND_VAL                                                 ~24
         35        DO_ICALL                                                 
   82    36        INIT_FCALL                                               'fputs'
         37        SEND_VAR                                                 !6
         38        ROPE_INIT                                     3  ~29     'Host%3A+'
         39        ROPE_ADD                                      1  ~29     ~29, !4
         40        ROPE_END                                      2  ~28     ~29, '%0D%0A'
         41        SEND_VAL                                                 ~28
         42        DO_ICALL                                                 
   84    43        IS_NOT_EQUAL                                             !3, ''
         44      > JMPZ                                                     ~32, ->52
   85    45    >   INIT_FCALL                                               'fputs'
         46        SEND_VAR                                                 !6
         47        ROPE_INIT                                     3  ~34     'Referer%3A+'
         48        ROPE_ADD                                      1  ~34     ~34, !3
         49        ROPE_END                                      2  ~33     ~34, '%0D%0A'
         50        SEND_VAL                                                 ~33
         51        DO_ICALL                                                 
   87    52    >   INIT_FCALL                                               'fputs'
         53        SEND_VAR                                                 !6
         54        SEND_VAR                                                 !2
         55        DO_ICALL                                                 
   89    56        INIT_FCALL                                               'fputs'
         57        SEND_VAR                                                 !6
         58        SEND_VAL                                                 'Content-type%3A+application%2Fx-www-form-urlencoded%0D%0A'
         59        DO_ICALL                                                 
   90    60        INIT_FCALL                                               'fputs'
         61        SEND_VAR                                                 !6
         62        STRLEN                                           ~39     !1
         63        CONCAT                                           ~40     'Content-length%3A+', ~39
         64        CONCAT                                           ~41     ~40, '%0D%0A'
         65        SEND_VAL                                                 ~41
         66        DO_ICALL                                                 
   91    67        INIT_FCALL                                               'fputs'
         68        SEND_VAR                                                 !6
         69        SEND_VAL                                                 'Connection%3A+close%0D%0A%0D%0A'
         70        DO_ICALL                                                 
   92    71        INIT_FCALL                                               'fputs'
         72        SEND_VAR                                                 !6
         73        SEND_VAR                                                 !1
         74        DO_ICALL                                                 
   94    75        ASSIGN                                                   !9, ''
   95    76      > JMP                                                      ->82
   97    77    >   INIT_FCALL                                               'fgets'
         78        SEND_VAR                                                 !6
         79        SEND_VAL                                                 128
         80        DO_ICALL                                         $46     
         81        ASSIGN_OP                                     8          !9, $46
   95    82    >   INIT_FCALL                                               'feof'
         83        SEND_VAR                                                 !6
         84        DO_ICALL                                         $48     
         85        BOOL_NOT                                         ~49     $48
         86      > JMPNZ                                                    ~49, ->77
         87    > > JMP                                                      ->95
  102    88    >   INIT_ARRAY                                       ~50     'err', 'status'
  103    89        ROPE_INIT                                     4  ~52     !8
         90        ROPE_ADD                                      1  ~52     ~52, '+%28'
         91        ROPE_ADD                                      2  ~52     ~52, !7
         92        ROPE_END                                      3  ~51     ~52, '%29'
         93        ADD_ARRAY_ELEMENT                                ~50     ~51, 'error'
         94      > RETURN                                                   ~50
  108    95    >   INIT_FCALL                                               'fclose'
         96        SEND_VAR                                                 !6
         97        DO_ICALL                                                 
  111    98        INIT_FCALL                                               'explode'
         99        SEND_VAL                                                 '%0D%0A%0D%0A'
        100        SEND_VAR                                                 !9
        101        SEND_VAL                                                 2
        102        DO_ICALL                                         $55     
        103        ASSIGN                                                   !9, $55
  113   104        ISSET_ISEMPTY_DIM_OBJ                         0          !9, 0
        105      > JMPZ                                                     ~57, ->109
        106    >   FETCH_DIM_R                                      ~58     !9, 0
        107        QM_ASSIGN                                        ~59     ~58
        108      > JMP                                                      ->110
        109    >   QM_ASSIGN                                        ~59     ''
        110    >   ASSIGN                                                   !10, ~59
  114   111        ISSET_ISEMPTY_DIM_OBJ                         0          !9, 1
        112      > JMPZ                                                     ~61, ->116
        113    >   FETCH_DIM_R                                      ~62     !9, 1
        114        QM_ASSIGN                                        ~63     ~62
        115      > JMP                                                      ->117
        116    >   QM_ASSIGN                                        ~63     ''
        117    >   ASSIGN                                                   !11, ~63
  118   118        INIT_ARRAY                                       ~65     'ok', 'status'
  119   119        ADD_ARRAY_ELEMENT                                ~65     !10, 'header'
  120   120        ADD_ARRAY_ELEMENT                                ~65     !11, 'content'
        121      > RETURN                                                   ~65
  122   122*     > RETURN                                                   null

End of function post_request

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.76 ms | 1408 KiB | 31 Q