file_get_contents performance

Do you need historical data? If not rather do updates than inserts.
 
Do you need historical data? If not rather do updates than inserts.

I do not think I need the historical data, I am not planning on building graphs anymore.

What is the difference between updates and inserts assuming you are referring to the my DB part in the script?
 
Oh wait you mean there is only n rows where n is the amount of shares and then each time the cron job runs it just updates the values?
 
On my phone but something like:

update stock_prices set price=123 where company='abc'
 
Oh my lord. This is probably how password resets/changes and profile changes works?

What a world.
 
On my phone but something like:

update stock_prices set price=123 where company='abc'

Well this worked.

I do not think I did it correctly I just went with my gut here, it works, but I have some questions ie, won't this mess up some stuff if I add 5 more stocks to my array?

Is there a way to have some condition like if stock doesnt exist add a new row if that makes sense.

2016-08-09_14-55-40.png
 
Sure, you could do a select to check if it exists and then do an insert or update as required. Or just manually create them to start then you only need updates.
 
Ahh okey that is sorted.

Now the what I assume is the hard part.

I want use a for loop to echo this for each instance of a stock:

PHP:
echo "<div class=\"stock"; if ($percentage >= 0) {echo ' green';} else { echo ' red';} echo "\" id=\"stock-1\">
<span class=\"symbol\">$company</span>
<span class=\"change\">";if ($percentage > 0) {echo '+';} else { echo '';} ;
echo $percentage;echo "%</span>";
echo "<br>";
echo "<span class=\"price\">$price cents</span>";
echo "</div>";

However now using a database I am a bit confused

In order to show what is in my DB I figured I need to do this:
PHP:
//Select Stocks to shpw

$sql = "SELECT company, price, percentage FROM stock_history";

$statement = $db->prepare($sql);
$statement->execute();

but now...

How do I assign the DB values to a variable:
$company
$price
$percentage

and echo those in a loop?

I was under the impression PDO::FETCH_ASSOC:
would give me this:

PHP:
(
    [company] => Taste
    [price] => 230
    [percentage] => 2
)

But my first attempt appears to be a fcking disaster of note.

2016-08-09_15-56-35.png

Undefined variable: percentage
 
Last edited:
I normally use mysqli not pdo

No go away sir.

I was k@ked out here in this very sub forum not too long ago and told from all sides that I MUST use pdo.

So there is not a chance in hell I am unlearning everything now and going back to mysqli just to have the API discontinued in the next php release.

:P

With pdo I assume I can easy switch to different databases as well which is nice, but I don't know if I'll use anything else since cpanel comes with phpmyadmin and mysql I assume?
 
Never heard of this PDO thing. But I use a framework.
 
Well whatever db link you use not so important. We use php-fpm on nginx and mysqli. We have 128Gb servers from DigitalOcean and runs smoothly.
 
Well whatever db link you use not so important. We use php-fpm on nginx and mysqli. We have 128Gb servers from DigitalOcean and runs smoothly.

Not bothered about this, this side chat is not?

I mean weather I use PDO, mysqli procedural or mysqli oo should make a difference to my end result should it?

Maybe I don't grasp the differences.

Please enlighten me with pros and cons

As I am learning along the way
 
Not bothered about this, this side chat is not?

I mean weather I use PDO, mysqli procedural or mysqli oo should make a difference to my end result should it?

Maybe I don't grasp the differences.

Please enlighten me with pros and cons

As I am learning along the way
It's got electrolytes.
 
Fcking succes!! Thank you @bio and @koeks

It works!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I learned, insert, update, select and cron jobs and pdo
 
You guys are amazing!

The initial script did 5 seconds.

By having that as a background process via cron and the view as a separate read from the db process we have now achieved this:

Code:
CoreShares Top 50 0%
2098 cents
Taste Holdings Ltd +2%
230 cents
Shoprite Holdings Ltd 0%
20598 cents
Capital & Counties Properties PLC 0%
5010 cents
Coronation Fund Managers Ltd +1%
7482 cents
db x-trackers - MSCI WORLD INDEX ETF -2%
2328 cents
EOH Holdings Ltd 0%
14310 cents
JSE Ltd -2%
17200 cents
[B]Time: 0.0029 Seconds[/B]

Now I am no expert, but 0.0029 seconds load time seems pretty acceptable to me?
 
You guys are amazing!

The initial script did 5 seconds.

By having that as a background process via cron and the view as a separate read from the db process we have now achieved this:

Code:
CoreShares Top 50 0%
2098 cents
Taste Holdings Ltd +2%
230 cents
Shoprite Holdings Ltd 0%
20598 cents
Capital & Counties Properties PLC 0%
5010 cents
Coronation Fund Managers Ltd +1%
7482 cents
db x-trackers - MSCI WORLD INDEX ETF -2%
2328 cents
EOH Holdings Ltd 0%
14310 cents
JSE Ltd -2%
17200 cents
[B]Time: 0.0029 Seconds[/B]

Now I am no expert, but 0.0029 seconds load time seems pretty acceptable to me?
Importance to debugging vital; importance to user inconsequential; its really about consumption time
 
Top
Sign up to the MyBroadband newsletter
X