PHP Scraper appears to be in an infinite loop
<p>(I'm scraping this stuff with the permission of the website in question, by the way).</p>

<p>Pretty simple web scraper, was working fine when I was loading all the links by hand, but when I've tried to load them in via JSON and variables (so I can do lots of scraping with the one script and make the process more modular by just adding more links to JSON) it runs on an infinite loop.</p>

<p>(Page has been loading for about 15 minutes now)</p>

<p>Here is my JSON. Only one store is in there for testing purposes but there is going to be about 15 more.</p>

<pre><code>[
   {
      "store":"Incu Men",
      "cat":"Accessories",
      "general_cat":"Accessories",
      "spec_cat":"accessories",
      "url":"http://www.incuclothing.com/shop-men/accessories/",
      "baseurl":"http://www.incuclothing.com",
      "next_select":"a.next",
      "prod_name_select":".infobox .fn",
      "label_name_select":".infobox .brand",
      "desc_select":".infobox .description",
      "price_select":"#price",
      "mainImg_select":"",
      "more_imgs":".product-images",
      "product_url":".hproduct .photo-link"
   }
]
</code></pre>

<p>Here is the PHP scraper code:</p>

<pre><code>&lt;?php
//Set infinite time limit
set_time_limit (0);
// Include simple html dom
include('simple_html_dom.php');
// Defining the basic cURL function
function curl($url) {
  $ch = curl_init();
    // Initialising cURL
    curl_setopt($ch, CURLOPT_URL, $url);
    // Setting cURL's URL option with the $url variable passed into the function
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    // Setting cURL's option to return the webpage data
    $data = curl_exec($ch);
    // Executing the cURL request and assigning the returned data to the $data variable
    curl_close($ch);
    // Closing cURL
    return $data;
    // Returning the data from the function
}

function getLinks($catURL, $prodURL, $baseURL, $next_select) {
    $urls = array();

    while($catURL) {
        echo "Indexing: $url" . PHP_EOL;
        $html = str_get_html(curl($catURL));

        foreach ($html-&gt;find($prodURL) as $el) {
            $urls[] = $baseURL . $el-&gt;href;
        }

        $next = $html-&gt;find($next_select, 0);
        $url = $next ? $baseURL . $next-&gt;href : null;

        echo "Results: $next" . PHP_EOL;
    }

    return $urls;
}

$string     = file_get_contents("jsonWorkers/incuMens.json");
$json_array = json_decode($string,true);

foreach ($json_array as $value){

    $baseURL = $value['baseurl'];
    $catURL = $value['url'];
    $store = $value['store'];
    $general_cat = $value['general_cat'];
    $spec_cat = $value['spec_cat'];
    $next_select = $value['next_select'];
    $prod_name = $value['prod_name_select'];
    $label_name = $value['label_name_select'];
    $description = $value['desc_select'];
    $price = $value['price_select'];
    $prodURL = $value['product_url'];

    if (!is_null($value['mainImg_select'])){
        $mainImg = $value['mainImg_select'];
    }
    $more_imgs = $value['more_imgs'];



    $allLinks = getLinks($catURL, $prodURL, $baseURL, $next_select);

}

?&gt;
</code></pre>

<p>Any ideas why the script would be running infinitely and not returning anything/stopping/printing anything to screen? I'm just gonna let it run until it stops. When I was doing this by hand it would only take a minute or so, sometimes less, so I'm sure it's a problem with my variables/json but I can't for the life of me see what the issues lie.</p>

<p>Can anyone take a quick look and point me in the right direction?</p>
