...

View Full Version : Create CSV on server



Scharfheimlich
01-29-2012, 03:36 PM
In Brno, 29.01.2012

Hello everybody,

i really need your help with one issue. I need any php which create .csv file on server every 2 minutes and fill in some data.

I need to track some stocks to .csv file. This file will be replaced every two minutes by new one (values will be changed).

for example:


I need to track 3 stocks: Google, Apple, Deutche Bank, i have solved how to get prices. I only need any php to create .csv file like this:

A1: "company", "price", "quantity in portfolio" and so on
B1: Google, 580.00, 13, ...
C1: Apple, 440.87, 23, ....
D1: Deutche Bank, 44.44, 130, ...
E1: next stock, price, quantity, ...
....
It would be perfect if that .csv file would be saved in special folder on my server.


I would really apreciate every help, thank you in advance!

Stefan alias "Scharfheimlich"

jmj001
01-29-2012, 06:27 PM
csv files are pretty easy to make


$csvData = 'A1: "company", "price", "quantity in portfolio" and so on\n
B1: Google, 580.00, 13, ...\n
C1: Apple, 440.87, 23, ....\n
D1: Deutche Bank, 44.44, 130, ...\n
E1: next stock, price, quantity, ...';
$dumpFile = 'my_csv_file.csv';

$fp = fopen($dumpFile, 'w');
fwrite($fp, $csvData);
fclose($fp);


then run it every 2 minutes with crontab

Scharfheimlich
01-29-2012, 07:01 PM
csv files are pretty easy to make


$csvData = 'A1: "company", "price", "quantity in portfolio" and so on\n
B1: Google, 580.00, 13, ...\n
C1: Apple, 440.87, 23, ....\n
D1: Deutche Bank, 44.44, 130, ...\n
E1: next stock, price, quantity, ...';
$dumpFile = 'my_csv_file.csv';

$fp = fopen($dumpFile, 'w');
fwrite($fp, $csvData);
fclose($fp);


then run it every 2 minutes with crontab

Thank you so much. I would very appreciate if you would give me also that crontab please. I am just an economist, i tried to run it using help from this page (http://adminschoice.com/crontab-quick-reference), but i was not successful...

Again really thank you!

jmj001
01-29-2012, 07:21 PM
you need to create a php script that you can manually run with your browser every however long...

then, when that is working and creating the csv file you are trying to make...

you can then automate the process by having the server process 'crontab' automatically run that php file for you...

but first you have to make the file/script to do the work you need done..

some pointers....
http://www.cyberciti.biz/faq/howto-setup-php-script-as-cronjob/
http://www.wallpaperama.com/forums/how-to-run-php-scripts-with-crontab-make-php-files-executable-t5657.html
http://support.modwest.com/content/5/125/en/can-i-run-a-php-script-on-cron.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum