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 5957811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:27:16+00:00 2026-05-22T18:27:16+00:00

I wasn’t able to find a question already answered on here that applied to

  • 0

I wasn’t able to find a question already answered on here that applied to my situation. From my understanding of what this code is doing, it should actually be working but I just don’t understand why it isn’t.

I’m reading a list of SKUs from a text file. Each SKU is on it’s own line. All I need to do is pass the SKU alone to my XML-RPC request and have it print the results. From the code I’m pasting below, It appears to loop through the SKUs but only one valid result is returned.

If I pass each SKU manually through the $request variable, I get valid results. I’ve been testing with 5 SKUs but I have 200 to actually do so it would be nice if I can get this to work. I even broke out the Lydia PHP training videos to see if I didn’t understand something but it didn’t seem like my code was wrong.

I appreciate your help with this.

<?php

$list = file("skus2.txt");
print_r($list);

foreach ($list as $sku){

  $server_url = "http://xxxx.xxx/webservices/index.php";
  $request = xmlrpc_encode_request("catalog.findProductImagesBySku", array($sku));
  $context = stream_context_create(array(
  'http' => array(
  'method' => "POST",
  'header' => "Content-Type: text/xml",
  'content' => $request)));
   $file = file_get_contents($server_url, false, $context);
   $response = xmlrpc_decode($file);
   print_r ($response);
      }
?>

I have tried this every which way it feels like. I’ve been at it for hours and hours.

This is what I’m getting in return. As you can see its failing on the first 4 even though from the print statement, it’s grabbing the right SKU and it’s successful on the last SKU. All the SKUs are valid because I tested them one at a time.

    Array
(
    [0] => DJ750605

    [1] => TO88116

    [2] => TO1112516

    [3] => TO1112506

    [4] => ENAI200006
)

//start of 1st run of foreach loop
DJ750605

Warning:  file_get_contents(http://xxx/webservices/index.php) [function.file-get-contents]: failed to open stream: HTTP request failed! ...

//start of 2nd run of foreach loop
TO88116

Warning:  file_get_contents(http://xxx/webservices/index.php) [function.file-get-contents]: failed to open stream: HTTP request failed!...


//start of 3rd run of foreach loop
TO1112516

Warning:  file_get_contents(http://xxx/webservices/index.php) [function.file-get-contents]: failed to open stream: HTTP request failed!...


//start of 4th run of foreach loop
TO1112506

Warning:  file_get_contents(http://xxx/webservices/index.php) [function.file-get-contents]: failed to open stream: HTTP request failed!...

//start of 5th run of foreach loop
ENAI200006Array
(
[0] => Array
    (
        [sku] => ENAI200006
        [large_url] => http://xxxENAI200006.JPG
        [medium_url] => http://xxxENAI200006.JPG
        [thumb_url] => http://xxxENAI200006.JPG
        [url] => http://xxxENAI200006.JPG
    )

)

UPDATE: Working Code 🙂

<pre>
<?php

$list = file('skus2.txt', FILE_IGNORE_NEW_LINES);
print_r($list);

foreach ($list as $sku){

$server_url = "http://xxx.com/xxx/webservices/index.php";
$request = xmlrpc_encode_request("catalog.findProductImagesBySku", array($sku));
$context = stream_context_create(array(
'http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request)));
$file = file_get_contents($server_url, false, $context);
$response = xmlrpc_decode($file);
print_r ($response);
}
?>
</pre>

Thanks again,
Cheers!

  • 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-05-22T18:27:17+00:00Added an answer on May 22, 2026 at 6:27 pm

    I’m suspicious of the call to file(‘skus2.txt’), as stated in the manual:

    Note:

    Each line in the resulting array will include the line ending, unless FILE_IGNORE_NEW_LINES is used, so you still need to use rtrim() if you do not want the line ending present.

    I would try either calling like this:

    $list = file('somefile.txt', FILE_IGNORE_NEW_LINES);
    

    Or even just passing the array manually to see if it works, ie:

    $list = array('TO88116',
                  'TO1112516',
                  'etc...'
                 );
    

    You at least reduce the scope of what you have to debug this way.

    Good-luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wasn't able to find a question/answer that covers this fully hence why I
Wasn't too sure exactly how to title this question, but here's the issue that
I wasn't sure what to title this question. Here's my goal: On page one,
I wasn't able to find documentation for this. It looks like the R source
Already checked the Internet but I wasn't able to find it out :-
Wasn't able to find a similar thread, so here goes. I just installed Kaminari
hope this wasn't asked already, but I can't find an answer. I got a
I wasn't able to find much about how to do this. I'm probably not
I wasn't 100% how to phrase this question. I have a request to a
I wasn't able to find out (googling, reading mysql reference manual) how to get

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.