Fopen errors in php

Hi All,

We have been developing a new website using php on a cpanel server for a few months now.

Today we have moved the website site across to the production server which also uses cPanel.

After we've made the migration, we come up against the following error.


Warning: fopen(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clientfoldername/public_html/finance/finance/index.php on line 70

Warning: fopen(http://ichart.yahoo.com/table.csv?s=AAA.AX&a=5&b=15&c=2015&d=6&e=15&f=2015&g=d&ignore=.csv): failed to open stream: no suitable wrapper could be found in /home/clientfoldername/public_html/finance/finance/index.php on line 70

Warning: fgets() expects parameter 1 to be resource, boolean given in /home/clientfoldername/public_html/finance/finance/index.php on line 70

Warning: Invalid argument supplied for foreach() in /home/clientfoldername/public_html/finance/finance/index.php on line 177

We have added this to a new php.ini in the public_html folder but the issue remains.

allow_url_fopen = On
allow_url_include = On

Any help would really be appreciated.
Cheryl LanderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Sounds like this is a security issue on the production server. Is this a shared server environment or dedicated?
hieloCommented:
>> We have added this to a new php.ini in the public_html folder but the issue remains.
Are you sure that the public_folder/php.ini is the php.ini that is being loaded/honored?  Create a new file named SWHosting-Info.php and put the following in it:
<?php
phpinfo();

Open in new window


Load the page from your browser and search for "Loaded Configuration File" and see if the path points to "public_folder/php.ini".
Cheryl LanderAuthor Commented:
Hi,

I have just done the phpinfo file in the same location.

The results are here.

allow_url_fopen      On
allow_url_include      On

Loaded Configuration File      /home/clientfoldername/public_html/php.ini
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

hieloCommented:
Try restarting the web server (and by that I mean the service, not the machine).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cheryl LanderAuthor Commented:
We currently dont have access to that. I can do once the hosting company opens. Do you feel this will resolve it?
hieloCommented:
php may be run as cgi or as a server module.  When it runs as cgi, the php.ini is loaded every time you make a request to a php file.  Thus, in this scenario, if you make a change to the php.ini you typically see the changes/effects right away.

By contrast, if it is running as server module, then php.ini is loaded only when the server starts.  Thus, you must restart the server every time you make changes.

Lastly, if the restarting still does not solve the problem, ask your host if they have  php_admin_value set for that particular setting, in which case you will need to ask them to make the change for you. More info on that here:
https://ma.ttias.be/php-php_value-vs-php_admin_value-and-the-use-of-php_flag-explained/

On another note, have you tried other alternatives, like curl perhaps:
        // create curl resource 
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, "http://ichart.yahoo.com/table.csv?s=AAA.AX&a=5&b=15&c=2015&d=6&e=15&f=2015&g=d&ignore=.csv"); 

        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 
        curl_close($ch);  

Open in new window

Ray PaseurCommented:
Check also for "safe mode" and "suhosin" - two security measures that can wreak havoc when they are not expected (or even when they are).

This worked for me, on my server.  You should be able to copy/paste:
http://iconoun.com/demo/temp_swhosting.php
<?php // demo/temp_swhosting.php

/**
 * http://www.experts-exchange.com/questions/28697388/Fopen-errors-in-php.html
 *
 * http://php.net/manual/en/book.curl.php
 */
error_reporting(E_ALL);

// FROM THE POST AT E-E
$url = 'http://ichart.yahoo.com/table.csv?s=AAA.AX&a=5&b=15&c=2015&d=6&e=15&f=2015&g=d&ignore=.csv';

// TRY THE REMOTE WEB SERVICE
$doc = my_curl($url);

// SHOW THE WORK PRODUCT OR BARK OUT ERROR MESSAGES
echo '<pre>';
echo PHP_EOL . '<strong>' . $url . '</strong>' . PHP_EOL;
echo PHP_EOL . htmlentities($doc);
echo PHP_EOL;


// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl
( $url
, $timeout=5
, $error_report=TRUE
)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE THIS BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );
    curl_setopt( $curl, CURLOPT_VERBOSE,        TRUE   );
    curl_setopt( $curl, CURLOPT_FAILONERROR,    TRUE   );

    // IF USING SSL, THIS INFORMATION MAY BE IMPORTANT
    // http://php.net/manual/en/function.curl-setopt.php#110457
    // http://php.net/manual/en/function.curl-setopt.php#115993
    // http://php.net/manual/en/function.curl-setopt.php#113754
    // REDACTED IN 2015 curl_setopt( $curl, CURLOPT_SSLVERSION, 3 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, FALSE  );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE  );


    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE
    if ($htm === FALSE)
    {
        // VISUALIZE ERROR MESSAGES
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN JSON / XML / HTML STRING
    curl_close($curl);
    return $htm;
}

Open in new window

Outputs:
http://ichart.yahoo.com/table.csv?s=AAA.AX&a=5&b=15&c=2015&d=6&e=15&f=2015&g=d&ignore=.csv

Date,Open,High,Low,Close,Volume,Adj Close
2015-07-14,50.13,50.13,50.12,50.13,31400,50.13
2015-07-13,50.11,50.12,50.11,50.12,13600,50.12
2015-07-10,50.11,50.12,50.11,50.11,75100,50.11
2015-07-09,50.10,50.11,50.10,50.11,34900,50.11
2015-07-08,50.12,50.12,50.10,50.10,10600,50.10
2015-07-07,50.12,50.12,50.10,50.11,39600,50.11
2015-07-06,50.10,50.11,50.09,50.09,73600,50.09
2015-07-03,50.10,50.10,50.08,50.08,49700,50.08
2015-07-02,50.10,50.10,50.08,50.09,43700,50.09
2015-07-01,50.09,50.09,50.07,50.09,92300,50.09
2015-06-30,50.19,50.19,50.10,50.18,80100,50.18
2015-06-29,50.18,50.20,50.18,50.18,52600,50.18
2015-06-26,50.19,50.19,50.17,50.17,132700,50.17
2015-06-25,50.17,50.19,50.17,50.17,53900,50.17
2015-06-24,50.16,50.18,50.16,50.18,52300,50.18
2015-06-23,50.17,50.18,50.16,50.16,104700,50.16
2015-06-22,50.16,50.17,50.15,50.15,211800,50.15
2015-06-19,50.15,50.17,50.15,50.16,143000,50.16
2015-06-18,50.16,50.16,50.14,50.14,18900,50.14
2015-06-17,50.15,50.16,50.14,50.14,42900,50.14
2015-06-16,50.13,50.15,50.13,50.15,241700,50.15
2015-06-15,50.13,50.15,50.13,50.15,61300,50.15

Open in new window

Cheryl LanderAuthor Commented:
Hi Guys,

Turned out to be the php ini had to actually be in the folder that the error was generated in?

We had placed in root and change it to the below.

/home/clientfoldername/public_html/finance/finance/php.ini

So not sure if this was a hosting server configuration, but we haven't had to do it this way before.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.