3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Call the Pardot API and get the raw XML response back * * @param string $url the full Pardot API URL to call, e.g. "https://pi.pardot.com/api/prospect/version/3/do/query" * @param array $data the data to send to the API - make sure to include your api_key and user_key for authentication * @param string $method GET", "POST", "DELETE" * @return string the raw XML response from the Pardot API * @throws Exception if we were unable to contact the Pardot API or something went wrong */ function callPardotApi($url, $data, $method = 'GET') { // build out the full url, with the query string attached. $queryString = http_build_query($data, null, '&'); if (strpos($url, '?') !== false) { $url = $url . '&' . $queryString; } else { $url = $url . '?' . $queryString; } $curl_handle = curl_init($url); // wait 5 seconds to connect to the Pardot API, and 30 // total seconds for everything to complete curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curl_handle, CURLOPT_TIMEOUT, 30); // https only, please! curl_setopt($curl_handle, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); // ALWAYS verify SSL - this should NEVER be changed. 2 = strict verify curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, 2); // return the result from the server as the return value of curl_exec instead of echoing it curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); if (strcasecmp($method, 'POST') === 0) { curl_setopt($curl_handle, CURLOPT_POST, true); } elseif (strcasecmp($method, 'GET') !== 0) { // perhaps a DELETE? curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, strtoupper($method)); } $pardotApiResponse = curl_exec($curl_handle); if ($pardotApiResponse === false) { // failure - a timeout or other problem. depending on how you want to handle failures, // you may want to modify this code. Some folks might throw an exception here. Some might // log the error. May you want to return a value that signifies an error. The choice is yours! // let's see what went wrong -- first look at curl $humanReadableError = curl_error($curl_handle); // you can also get the HTTP response code $httpResponseCode = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); // make sure to close your handle before you bug out! curl_close($curl_handle); throw new Exception("Unable to successfully complete Pardot API call to $url -- curl error: \"". "$humanReadableError\", HTTP response code was: $httpResponseCode"); } // make sure to close your handle before you bug out! curl_close($curl_handle); return $pardotApiResponse; } //this will log in and print your API Key (good for 1 hour) to the console $rz_key = callPardotApi('https://pi.pardot.com/api/login/version/3', array( 'email' => 'myemail@email.com', 'password' => 'password', 'user_key' => '032222222222222b75a192daba28d' ) ); $number_url = 'https://pi.pardot.com/api/prospect/version/3/do/query'; $number_url .= '?user_key=032222222222222b75a192daba28d'; $number_url .= '&api_key='; $number_url .= $rz_key; $number_url .= '&list_id=97676'; $number_url = preg_replace('/\s+/', '', $number_url); echo $number_url;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uCfiD
function name:  (null)
number of ops:  18
compiled vars:  !0 = $rz_key, !1 = $number_url
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   71     0  E >   INIT_FCALL                                               'callpardotapi'
          1        SEND_VAL                                                 'https%3A%2F%2Fpi.pardot.com%2Fapi%2Flogin%2Fversion%2F3'
   73     2        SEND_VAL                                                 <array>
          3        DO_FCALL                                      0  $2      
   71     4        ASSIGN                                                   !0, $2
   79     5        ASSIGN                                                   !1, 'https%3A%2F%2Fpi.pardot.com%2Fapi%2Fprospect%2Fversion%2F3%2Fdo%2Fquery'
   80     6        ASSIGN_OP                                     8          !1, '%3Fuser_key%3D032222222222222b75a192daba28d'
   81     7        ASSIGN_OP                                     8          !1, '%26api_key%3D'
   82     8        ASSIGN_OP                                     8          !1, !0
   83     9        ASSIGN_OP                                     8          !1, '%26list_id%3D97676'
   85    10        INIT_FCALL                                               'preg_replace'
         11        SEND_VAL                                                 '%2F%5Cs%2B%2F'
         12        SEND_VAL                                                 ''
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !1, $9
   87    16        ECHO                                                     !1
         17      > RETURN                                                   1

Function callpardotapi:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 70
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 115
Branch analysis from position: 91
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 115
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 85
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 115
Branch analysis from position: 91
Branch analysis from position: 115
Branch analysis from position: 85
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 70
Branch analysis from position: 63
Branch analysis from position: 70
filename:       /in/uCfiD
function name:  callPardotApi
number of ops:  120
compiled vars:  !0 = $url, !1 = $data, !2 = $method, !3 = $queryString, !4 = $curl_handle, !5 = $pardotApiResponse, !6 = $humanReadableError, !7 = $httpResponseCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'GET'
   14     3        INIT_FCALL                                               'http_build_query'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 null
          6        SEND_VAL                                                 '%26'
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !3, $8
   15     9        INIT_FCALL                                               'strpos'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 '%3F'
         12        DO_ICALL                                         $10     
         13        TYPE_CHECK                                  1018          $10
         14      > JMPZ                                                     ~11, ->19
   16    15    >   CONCAT                                           ~12     !0, '%26'
         16        CONCAT                                           ~13     ~12, !3
         17        ASSIGN                                                   !0, ~13
         18      > JMP                                                      ->22
   18    19    >   CONCAT                                           ~15     !0, '%3F'
         20        CONCAT                                           ~16     ~15, !3
         21        ASSIGN                                                   !0, ~16
   21    22    >   INIT_FCALL_BY_NAME                                       'curl_init'
         23        SEND_VAR_EX                                              !0
         24        DO_FCALL                                      0  $18     
         25        ASSIGN                                                   !4, $18
   25    26        INIT_FCALL_BY_NAME                                       'curl_setopt'
         27        SEND_VAR_EX                                              !4
         28        FETCH_CONSTANT                                   ~20     'CURLOPT_CONNECTTIMEOUT'
         29        SEND_VAL_EX                                              ~20
         30        SEND_VAL_EX                                              5
         31        DO_FCALL                                      0          
   26    32        INIT_FCALL_BY_NAME                                       'curl_setopt'
         33        SEND_VAR_EX                                              !4
         34        FETCH_CONSTANT                                   ~22     'CURLOPT_TIMEOUT'
         35        SEND_VAL_EX                                              ~22
         36        SEND_VAL_EX                                              30
         37        DO_FCALL                                      0          
   29    38        INIT_FCALL_BY_NAME                                       'curl_setopt'
         39        SEND_VAR_EX                                              !4
         40        FETCH_CONSTANT                                   ~24     'CURLOPT_PROTOCOLS'
         41        SEND_VAL_EX                                              ~24
         42        FETCH_CONSTANT                                   ~25     'CURLPROTO_HTTPS'
         43        SEND_VAL_EX                                              ~25
         44        DO_FCALL                                      0          
   32    45        INIT_FCALL_BY_NAME                                       'curl_setopt'
         46        SEND_VAR_EX                                              !4
         47        FETCH_CONSTANT                                   ~27     'CURLOPT_SSL_VERIFYHOST'
         48        SEND_VAL_EX                                              ~27
         49        SEND_VAL_EX                                              2
         50        DO_FCALL                                      0          
   35    51        INIT_FCALL_BY_NAME                                       'curl_setopt'
         52        SEND_VAR_EX                                              !4
         53        FETCH_CONSTANT                                   ~29     'CURLOPT_RETURNTRANSFER'
         54        SEND_VAL_EX                                              ~29
         55        SEND_VAL_EX                                              1
         56        DO_FCALL                                      0          
   37    57        INIT_FCALL                                               'strcasecmp'
         58        SEND_VAR                                                 !2
         59        SEND_VAL                                                 'POST'
         60        DO_ICALL                                         $31     
         61        IS_IDENTICAL                                             $31, 0
         62      > JMPZ                                                     ~32, ->70
   38    63    >   INIT_FCALL_BY_NAME                                       'curl_setopt'
         64        SEND_VAR_EX                                              !4
         65        FETCH_CONSTANT                                   ~33     'CURLOPT_POST'
         66        SEND_VAL_EX                                              ~33
         67        SEND_VAL_EX                                              <true>
         68        DO_FCALL                                      0          
         69      > JMP                                                      ->85
   39    70    >   INIT_FCALL                                               'strcasecmp'
         71        SEND_VAR                                                 !2
         72        SEND_VAL                                                 'GET'
         73        DO_ICALL                                         $35     
         74        IS_NOT_IDENTICAL                                         $35, 0
         75      > JMPZ                                                     ~36, ->85
   41    76    >   INIT_FCALL_BY_NAME                                       'curl_setopt'
         77        SEND_VAR_EX                                              !4
         78        FETCH_CONSTANT                                   ~37     'CURLOPT_CUSTOMREQUEST'
         79        SEND_VAL_EX                                              ~37
         80        INIT_FCALL                                               'strtoupper'
         81        SEND_VAR                                                 !2
         82        DO_ICALL                                         $38     
         83        SEND_VAR_NO_REF_EX                                       $38
         84        DO_FCALL                                      0          
   44    85    >   INIT_FCALL_BY_NAME                                       'curl_exec'
         86        SEND_VAR_EX                                              !4
         87        DO_FCALL                                      0  $40     
         88        ASSIGN                                                   !5, $40
   45    89        TYPE_CHECK                                    4          !5
         90      > JMPZ                                                     ~42, ->115
   51    91    >   INIT_FCALL_BY_NAME                                       'curl_error'
         92        SEND_VAR_EX                                              !4
         93        DO_FCALL                                      0  $43     
         94        ASSIGN                                                   !6, $43
   54    95        INIT_FCALL_BY_NAME                                       'curl_getinfo'
         96        SEND_VAR_EX                                              !4
         97        FETCH_CONSTANT                                   ~45     'CURLINFO_HTTP_CODE'
         98        SEND_VAL_EX                                              ~45
         99        DO_FCALL                                      0  $46     
        100        ASSIGN                                                   !7, $46
   57   101        INIT_FCALL_BY_NAME                                       'curl_close'
        102        SEND_VAR_EX                                              !4
        103        DO_FCALL                                      0          
   59   104        NEW                                              $49     'Exception'
        105        ROPE_INIT                                     3  ~51     'Unable+to+successfully+complete+Pardot+API+call+to+'
        106        ROPE_ADD                                      1  ~51     ~51, !0
        107        ROPE_END                                      2  ~50     ~51, '+--+curl+error%3A+%22'
   60   108        ROPE_INIT                                     3  ~54     !6
        109        ROPE_ADD                                      1  ~54     ~54, '%22%2C+HTTP+response+code+was%3A+++++'
        110        ROPE_END                                      2  ~53     ~54, !7
        111        CONCAT                                           ~56     ~50, ~53
        112        SEND_VAL_EX                                              ~56
        113        DO_FCALL                                      0          
        114      > THROW                                         0          $49
   64   115    >   INIT_FCALL_BY_NAME                                       'curl_close'
        116        SEND_VAR_EX                                              !4
        117        DO_FCALL                                      0          
   66   118      > RETURN                                                   !5
   67   119*     > RETURN                                                   null

End of function callpardotapi

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.86 ms | 1411 KiB | 24 Q