0

Here is how I am making a REST API Call and my url is in $url below. I am running it on WAMP server and basically I have saved this php(test.php) file www folder and when I execute the url (localhost//test.php), I get 500 Internal Server error. I basically want to run the URL($url) when I run the PHP script. How should I overcome this problem?

<?php 
    $method = "POST";
    $accessKey = "myaccesskey";
    $secretKey = "mysecretkey";
    date_default_timezone_set("UTC");
    $timeString = date("D, d M Y H:m:s", time()) . ' GMT'; 
    $url = "http://myurl.com";
    $signature = GenerateSignature($secretKey, $method, $timeString);
    $authorization = $accessKey . ":" . $signature;
    $ListDEsc = "test new description";
    $data = "ListDEsc=" . $ListDEsc;
    var_dump(CallAPI($method, $url, $timeString, $authorization, $data));  

    function CallAPI($method, $url, $timeString, $authorization, $data = false)
    {
        $curl = curl_init();

        switch ($method)
        {
            case "POST":
                curl_setopt($curl, CURLOPT_POST, 1);

                if ($data)
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                break;
            case "PUT":
                curl_setopt($curl, CURLOPT_PUT, 1);
                break;
            default:
                if ($data)
                    $url = sprintf("%s?%s", $url, http_build_query($data));
        }

        $accept = 'application/json';

        an so on...

The following post looks promising at the start but their goal was different than mine.

Error Log:

In C:\wamp\logs

I see two newly created files apache_error and php_error.

Inside php_error I have the following:

[22-Jul-2014 16:40:53 UTC] PHP Warning:  PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.5.12/ext/php_ldap.dll' - The specified module could not be found.

 in Unknown on line 0   

Inside apache_error I have the following:

[Tue Jul 22 09:40:44.898375 2014] [mpm_winnt:notice] [pid 7672:tid 404] AH00455: Apache/2.4.9 (Win32) PHP/5.5.12 configured -- resuming normal operations
[Tue Jul 22 09:40:44.959381 2014] [mpm_winnt:notice] [pid 7672:tid 404] AH00456: Apache Lounge VC11 Server built: Mar 16 2014 12:13:13
[Tue Jul 22 09:40:44.959381 2014] [core:notice] [pid 7672:tid 404] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.9\\bin\\httpd.exe -d C:/wamp/bin/apache/apache2.4.9'
[Tue Jul 22 09:40:45.031389 2014] [mpm_winnt:notice] [pid 7672:tid 404] AH00418: Parent: Created child process 7148
[Tue Jul 22 09:40:54.412327 2014] [mpm_winnt:notice] [pid 7148:tid 320] AH00354: Child: Starting 64 worker threads.

Error on Browser Looks Like:

string '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>

<title>500 - Internal server error.</title>

<style type="text/css">

<!--

body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}

fieldset{padding:0 15px 10px 15px;} 

h1{font-size:2.4em;margin:0;color:#FFF;}

h2{font-size:1.7'... (length=2007)

Test Done to see the working of Curl

Ran the following script:

<?php
  $curl_handle=curl_init();
  curl_setopt($curl_handle,CURLOPT_URL,'http://www.google.com');
  curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
  curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
  $buffer = curl_exec($curl_handle);
  curl_close($curl_handle);
  if (empty($buffer)){
      print "Nothing returned from url.<p>";
  }
  else{
      print $buffer;
  }
?>

Source of above Script: And I was successfully directed to google.com web page.

Community
  • 1
  • 1
rocky
  • 435
  • 3
  • 8
  • 18
  • Anything in your error log? – Stefan Jul 22 '14 at 17:40
  • @Stefan Where exactly I can check my error log? – rocky Jul 22 '14 at 17:46
  • See http://stackoverflow.com/questions/19713001/where-can-i-find-the-wamp-error-log – Stefan Jul 22 '14 at 17:47
  • @Stefan I updated my question with the error logs. Please see. – rocky Jul 22 '14 at 17:52
  • Looks like you are missing your `ldap` module. If you are not using this module, you should remove it's reference from the relevant `php.ini` file. – Lix Jul 22 '14 at 17:53
  • LDAP is not the problem here. Too bad that the error log doens't show you more information. Did you tried to manually debug the file? In other words strip the code down a bit and see what's causing the 500 error? – Stefan Jul 22 '14 at 17:58
  • @Stefan I haven't done that.Basically all code revolves around the function. I updated the exact error message I am getting in my browser. Please take a look. – rocky Jul 22 '14 at 18:06
  • That is the source code of a standard 500 error page ;-) I suggest that you try to build up your cURL configuration. Even though that you will not get data back until you authenticate, you should see an error message about that. Having a 500 error without a proper reason in the log file is like walking in the dark, – Stefan Jul 22 '14 at 18:10
  • @Stefan Thanks. I tried doing here stackoverflow.com/questions/24876726/saw-extension-php-curl-dll-already-enabled-in-php-ini Do you thing I should be following anything else? – rocky Jul 22 '14 at 18:19
  • @Stefan, I did a small test (updated in my question) for curl. Do you think that I still need any configuration? – rocky Jul 22 '14 at 18:32
  • Good that this works, now try to add the configuration like you have in the original script. On a moment you should reach the code that throws the internal server error – Stefan Jul 22 '14 at 19:38
  • Have a look in the Event Viewer for messages from Apache to see if there is anythng more useful there. – RiggsFolly Jul 23 '14 at 08:41

1 Answers1

0

To make sure that you have all the correct SYMLINK's generated into your Apache/bin folder do the following.

Click the Apache version number using the wampmanager menu's to force Wampmanager to redo the SYMLINK generation.

cURL uses the libeay32.dll and ssleay32.dll and possibly the SYMLINKS for those 2 libraries have not been created.

wampmanager -> Apache -> Version -> Apache -> 2.4.9
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • I did what you mention but still getting same error. By the way, if what you have mentioned would have been problem then my testing code would not have worked. Am I right? – rocky Jul 23 '14 at 17:01