120秒后504

I have this code

$url="site.com";//~
$opts=array(
    'http'=>array(
        'method'=>"GET",
        'header'=>"Accept: */*i
".
              "User-Agent: Your application name
",
        "ignore_errors" => true,
        "timeout" => 1800
    ),
    "ssl"=>array(
        "allow_self_signed"=>true,
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    )
);
$page = file_get_contents($url, false, stream_context_create($opts));
...
...

If $url (web page) is small size - script works well.

But when the size is large, and the running time begins to exceed 120 seconds -

process is going to abort and displayed 504 ERROR.

--

At the beginning of the script I add:

ini_set('max_execution_time',18000);
ini_set('default_socket_timeout',18000);
ignore_user_abort(true);
ini_set('memory_limit','512M');

In ini.php i add following:

max_execution_time = 18000;
max_input_time = 18000;

But nothing helps.

Question: How can i extend script execution time - more than 120 seconds ?

PS: All of the above (max_execution_time, ...) changed according to the specified intagers (as seen by phpinfo()). But parameters realpath_cache_size and realpath_cache_ttl (in phpinfo() written that equals 120) doesn't change. Maybe a problem on this ?

Your code is running for as long as you set it , Infact if you simply add to the top of your code

       set_time_limit(0);

It's won't stop till it's end, However if you want to keep waiting for the output then you need to set the Apache2 timeout limit, and also your browser timeout limit.