Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:39+00:00 2026-06-11T21:23:39+00:00

I am using cURL via PHP to test service connections, and I’m getting some

  • 0

I am using cURL via PHP to test service connections, and I’m getting some inconsistent results. When I run the test via PHP & cURL this is my result:

{"response":"\n\n\n\n \n \n 

When I put that same URL in my browser I get this:

{"response":"\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n    <link href=\"/images/global/global.css\...and so on

The response in my browser is cut short, but you get the idea.

With my PHP, I read in a JSON file, parse out the URL I need and the use cURL to send a GET request. Here is the code that I am using to test the service via PHP:

<?php
include ("serviceURLs.php"); 

class callService {
    function testService($url){

        $ch = curl_init($url);

        curl_exec($ch); 

        $info = curl_getinfo($ch); 
        if ($info['http_code'] == 200){
            echo("Test has passed </br>"); 
        }else{
            echo("Test Failed.</br> "); 
        }

        var_dump($info); 

        curl_close($ch); 
    }

    function readFile(){
        $myFile = "./service/catalog-adaptation.json"; 
        $fr = fopen($myFile, 'r');
        $fileData = fread($fr, filesize($myFile)); 
        $json_a = json_decode($fileData, TRUE); 

        $prodServer = $json_a['serverRoots']['%SERVER_ROOT']['PROD']; 
        $demoServer = $json_a['serverRoots']['%SERVER_ROOT']['DEMO']; 
        $testServer = $json_a['serverRoots']['%SERVER_ROOT']['TEST']; 

        $testUrls = $json_a['commands'];     
        foreach($testUrls as $tURL){
            $mURL =  $tURL['URL']; 

            if(stripos($mURL, "%")===0){
                $testTestService = str_replace("%SERVER_ROOT", $testServer, $mURL); 
                $testDemoService = str_replace("%SERVER_ROOT", $demoServer, $mURL); 
                $testProdService = str_replace("%SERVER_ROOT", $prodServer, $mURL); 

                echo ("Production test: "); 
                $this->testService($testProdService); 

                echo ("Demo test: "); 
                $this->testService($testDemoService); 

                echo ("Test test: "); 
                $this->testService($testTestService); 
            }
        }
    }
}
$newServiceTest = new callService;
$newServiceTest->readFile(); 
?>

Can anyone tell my why I am getting different results and how I can fix my code so I can get consistent results?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:23:41+00:00Added an answer on June 11, 2026 at 9:23 pm

    You need to set below option for return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using CURL via a php script running as daily cron to
Scenario: Sending XML, generated using php, via cURL to an external server for parsing.
I'm trying to post to WordPress using curl via PHP - I'm posting using
I'm using PHP cURL module to extract timestamp of a remote file via HTTP
Im using php, using curl Im accessing a directory on a server via http
I am trying to log in a website using php via cURL. But the
I have some code that is using the PHP cURL library to upload some
Im using curl to fetch my Twitter favorites: <?php $username = bob; $password =
I'm using Curl via Proxies to download images with a scraper I have developed.
I'm sending a string of data via CURL using data from post, and receiving

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.