kingb00zer Posted June 8, 2016 Share Posted June 8, 2016 Hi on occasion I get the error pasted below and am wondering if there is a way for it to either not be displayed or for it to not give up after 30 seconds? thanks Fatal error: Maximum execution time of 30 seconds exceeded in Link to comment Share on other sites More sharing options...
Don E Posted June 8, 2016 Share Posted June 8, 2016 The default max execution time for PHP scripts is 30 seconds. If ran longer than that, you get an error like the one you saw. You can increase the execution time in your php.ini file by increasing the max_execution_time directive. Link to comment Share on other sites More sharing options...
kingb00zer Posted June 8, 2016 Author Share Posted June 8, 2016 thank you, ill have a look at that file. if I have any issues changing it ill let you know. Link to comment Share on other sites More sharing options...
kingb00zer Posted June 8, 2016 Author Share Posted June 8, 2016 ok so I have no idea what to do, where do I go? Link to comment Share on other sites More sharing options...
Ingolme Posted June 8, 2016 Share Posted June 8, 2016 Show us your code. Something in your code is taking far too long to run, it could be an infinite loop or a slow MySQL query. Link to comment Share on other sites More sharing options...
kingb00zer Posted June 9, 2016 Author Share Posted June 9, 2016 Show us your code. Something in your code is taking far too long to run, it could be an infinite loop or a slow MySQL query. the code is pasted below, I created something based around some code I found form a google search which gives me stock prices from yahoo finance. its only ever shows me this error 50% of the time while the market is closed. its no big deal if I can extend the time I just need to know how to change that time. <?php /** * Class to fetch stock data from Yahoo! Finance * */ class YahooStock { /** * Array of stock code */ private $stocks = array(); /** * Parameters string to be fetched */ private $format; /** * Populate stock array with stock code * * @param string $stock Stock code of company * @return void */ public function addStock($stock) { $this->stocks[] = $stock; } /** * Populate parameters/format to be fetched * * @param string $param Parameters/Format to be fetched * @return void */ public function addFormat($format) { $this->format = $format; } /** * Get Stock Data * * @return array */ public function getQuotes() { $result = array(); $format = $this->format; foreach ($this->stocks as $stock) { /** * fetch data from Yahoo! * s = stock code * f = format * e = filetype */ $s = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=$format&e=.csv"); // this is the line that causes the fatal error (sometimes) /** * convert the comma separated data into array */ $data = explode( ',', $s); /** * populate result array with stock code as key */ $result[$stock] = $data; } return $result; } } Link to comment Share on other sites More sharing options...
Ingolme Posted June 9, 2016 Share Posted June 9, 2016 This looks like an answer that will work: http://stackoverflow.com/questions/10236166/does-file-get-contents-have-a-timeout-setting But you could use PHP's cURL library instead of file_get_contents(). cURL is better suited for accessing files from remote servers. Link to comment Share on other sites More sharing options...
kingb00zer Posted June 9, 2016 Author Share Posted June 9, 2016 I tried playing around with the curls first but i dont really understand it just yet and am limited on time at the moment so i chose to use this. ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes I dont know if I put it in the right place as Im still getting the same error. <?php /** * Class to fetch stock data from Yahoo! Finance * */ class YahooStock { /** * Array of stock code */ private $stocks = array(); /** * Parameters string to be fetched */ private $format; /** * Populate stock array with stock code * * @param string $stock Stock code of company * @return void */ public function addStock($stock) { $this->stocks[] = $stock; } /** * Populate parameters/format to be fetched * * @param string $param Parameters/Format to be fetched * @return void */ public function addFormat($format) { $this->format = $format; } /** * Get Stock Data * * @return array */ public function getQuotes() { $result = array(); $format = $this->format; foreach ($this->stocks as $stock) { /** * fetch data from Yahoo! * s = stock code * f = format * e = filetype */ ini_set('default_socket_timeout', 900); // 900 Seconds = 15 Minutes $s = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=$format&e=.csv"); /** * convert the comma separated data into array */ $data = str_getcsv($s, ",", '"'); /** * populate result array with stock code as key */ $result[$stock] = $data; } return $result; } } Link to comment Share on other sites More sharing options...
Ingolme Posted June 9, 2016 Share Posted June 9, 2016 The socket timeout isn't the problem, it's PHP's execution time that's the problem. You can increase the amount of time PHP is allowed to execute using set_time_limit(). Link to comment Share on other sites More sharing options...
kingb00zer Posted June 10, 2016 Author Share Posted June 10, 2016 Thank you I will try it out, if I have any issues ill report back to this thread. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now