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

  • Home
  • SEARCH
  • 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 9140235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:22+00:00 2026-06-17T09:29:22+00:00

At the moment i’m trying to save stock data from loading csv files of

  • 0

At the moment i’m trying to save stock data from loading csv files of yahoo. I created a database called stocks with that constitutes the ticker names of NASDAQ/NYSE/AMEX as tables ( about 6,5 K tables).
the problem ist the saving of the data i get is taking way too long.
I want to load an save the datas in 1 minute ticks. the loading takes me about 30 seconds and the saving about 3 mins. i have to reduce the saving time.
here is the script i wrote for geting and saving the data:

 include('mysql_connect.php');

 $ticker=array();
 $db="stocks";
 $res=mysql_query("SHOW TABLES FROM $db");
 while($row=mysql_fetch_array($res,MYSQL_NUM)){
    $ticker[]=$row[0];
 }

 $ticker_length=count($ticker);
 $steps=floor($ticker_length/200);

for($j=0;$j<=$steps;$j++){
    $ticker_url="";
    if($j<$steps){
        for($i=$j*200;$i<($j+1)*200;$i++){
            if($i==(($j+1)*200)-1){
                $ticker_url=$ticker_url.$ticker[$i];
            }else{
                $ticker_url=$ticker_url.$ticker[$i]."+";
            }
        }

    $url="http://finance.yahoo.com/d/quotes.csv?s='$ticker_url'&f=snxab2l1va2p2opm3m4ghd1t1=.csv";
    $filehandle=fopen("$url","r");
    while(!feof($filehandle)){

        $line=fgetcsv($filehandle,1024);
        if( $line[0]=="" || $line[0]==null || !isset($line[0]) ){
            //echo"Leer<br/>";
        }else{
            $Symbol=strtolower($line[0]);
            $Name=$line[1];
            $LastTradePriceOnly=$line[5];
            $Volume=$line[6];


                    $query=mysql_query("INSERT INTO $Symbol(symbol,Name,LastTradePriceOnly,Volume) 
                    VALUES('$Symbol','$Name','$LastTradePriceOnly','$Volume')");
        }

     }
     fclose($filehandle);   

    }else{
        for($i=$j*200;$i<$ticker_length;$i++){
            if($i==$ticker_length-1){
                $ticker_url=$ticker_url.$ticker[$i];
            }else{
                $ticker_url=$ticker_url.$ticker[$i]."+";
            }
        }

    $url="http://finance.yahoo.com/d/quotes.csv?s='$ticker_url'&f=snxab2l1va2p2opm3m4ghd1t1=.csv";
    $filehandle=fopen("$url","r");
    while(!feof($filehandle)){

        $line=fgetcsv($filehandle,1024);
        if( $line[0]=="" || $line[0]==null || !isset($line[0]) ){
            //echo"empty<br/>";
        }else{
            $Symbol=strtolower($line[0]);
            $Name=$line[1];
            $LastTradePriceOnly=$line[5];
            $Volume=$line[6];

                    $query=mysql_query("INSERT INTO $Symbol(symbol,Name,LastTradePriceOnly,Volume) 
                    VALUES('$Symbol','$Name','$LastTradePriceOnly','$Volume')");
        }

     }
     fclose($filehandle);
    }
}

so now i want to know:

  1. Is there a way of saving faster by changing the script?
  2. I know that there is the possibility of configuring mysql settings like buffer_size etc. How i can do that and what i have got to change?
  3. if this the saving time i require i not possible with mysql, what alternatives are out there?

would be pleased by getting some help.

thanks.

  • 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-06-17T09:29:23+00:00Added an answer on June 17, 2026 at 9:29 am

    i have found the solution. Mysql allows you to save your lines and cols from csv without reading the lines in complex loops:

        $url = "http://finance.yahoo.com/d/quotes.csv?s=AAPL+MSFT+GOOG&f=...the datas you need=.csv";
    
        $sql = "LOAD DATA LOCAL INFILE '" . $url . "' 
        INTO TABLE `" . $data_tablename . "` 
        FIELDS 
        TERMINATED BY ',' 
        OPTIONALLY ENCLOSED BY '\"' 
        LINES 
        TERMINATED BY '\n' 
        (`your_cols`,``,.....)";
    
         mysql_query($sql)or die(mysql_error());
    

    my script took me 250 sec on the server but now just 45 sec’s. Amazing profit of time….

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

Sidebar

Related Questions

At this moment i am trying to get a double value from textbox like
At the moment I am trying to HTTP response request in my Sharepoint WarmUp
At the moment I'm trying to figure out how use default and custom settings
At the moment I am just trying to get jquery to show an alert
At the moment I am trying to declare a global object in c++ as
At the moment I am using a custom class derived from HashSet . There's
At the moment I'm trying to use Python to detect when the left mouse
At the moment I am working on creating a small library for common data
at the moment I have a small application and need to take information from
At the moment I have a class that requires information from another class, but

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.