473,626 Members | 3,316 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting prices from external e-commerce system

I'm using the code below to retrieve price data from my e-commerce
provider. The plan being to only have prices stored in one location
and for there to be correct real-time currency conversions.
Using the URL in $url I can get the product price for any quatity or
currency. Initially I was just using fopen to get the data but on
occasion the URL would fail due to timeouts (network congestion,
ecommerce server busy or failure, etc) etc. So now when a good
response has occured I store this in file in the prices directory, if
a failure occurs in the future then I can use the stored price
instead. Typically, my web pages would display prices in pounds,
dollars and euro. Traffic levels aren't very high, maybe 100 hits per
day.
Can anyone see any problems here or are there better ways of doing
this? I think a database would be overkill for this and may even cause
more reliability problems than I'm trying to fix.
MTIA
<?php
function ContractPriceFo rCurrency($cont ract, $quantity, $currency) {
$filename = 'prices/' . $contract . $quantity . $currency .
'.txt';
$url = 'http://www.xxxx.com/jsp/get_local_price .jsp?contractId =' .
$contract . '&quantity=' . $quantity . '&currency=' . $currency .
'&responseType= number';

$c = curl_init($url) ;
curl_setopt($c, CURLOPT_TIMEOUT , 1);
curl_setopt($c, CURLOPT_CONNECT TIMEOUT, 1);
curl_setopt($c, CURLOPT_RETURNT RANSFER, 1);
$price = curl_exec($c);
$price = trim($price);
curl_close($c);

// if a price has been returned then store it and use it
if ($price !== '') {
$fd = fopen($filename ,"w");
fwrite($fd, $price);
fclose($fd);
} else {
// otherwise use the stored value
$fd = fopen($filename ,"r");
$price = fread($fd, filesize($filen ame));
fclose($fd);
$price = trim($price);
}

return $price;
}
?>

--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/ http://www.pherber.com/
Oct 6 '08 #1
6 1375
Paul Herber wrote:
I'm using the code below to retrieve price data from my e-commerce
provider. The plan being to only have prices stored in one location
and for there to be correct real-time currency conversions.
Using the URL in $url I can get the product price for any quatity or
currency. Initially I was just using fopen to get the data but on
occasion the URL would fail due to timeouts (network congestion,
ecommerce server busy or failure, etc) etc. So now when a good
response has occured I store this in file in the prices directory, if
a failure occurs in the future then I can use the stored price
instead. Typically, my web pages would display prices in pounds,
dollars and euro. Traffic levels aren't very high, maybe 100 hits per
day.
Can anyone see any problems here or are there better ways of doing
this? I think a database would be overkill for this and may even cause
more reliability problems than I'm trying to fix.
MTIA
<?php
function ContractPriceFo rCurrency($cont ract, $quantity, $currency) {
$filename = 'prices/' . $contract . $quantity . $currency .
'.txt';
$url = 'http://www.xxxx.com/jsp/get_local_price .jsp?contractId =' .
$contract . '&quantity=' . $quantity . '&currency=' . $currency .
'&responseType= number';

$c = curl_init($url) ;
curl_setopt($c, CURLOPT_TIMEOUT , 1);
curl_setopt($c, CURLOPT_CONNECT TIMEOUT, 1);
curl_setopt($c, CURLOPT_RETURNT RANSFER, 1);
$price = curl_exec($c);
$price = trim($price);
curl_close($c);

// if a price has been returned then store it and use it
if ($price !== '') {
$fd = fopen($filename ,"w");
fwrite($fd, $price);
fclose($fd);
} else {
// otherwise use the stored value
$fd = fopen($filename ,"r");
$price = fread($fd, filesize($filen ame));
fclose($fd);
$price = trim($price);
}

return $price;
}
?>
A database is definitely NOT overkill, and will cause FEWER reliability
problems.

For instance - any time you open a file for writing (or might have it
open for writing), you need to flock() the file to ensure it isn't
accessed by another script while it is being updated.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 6 '08 #2
On 6 Oct, 11:58, Paul Herber <SubstituteMyFi rstNameH...@phe rber.com>
wrote:
I'm using the code below to retrieve price data from my e-commerce
provider. The plan being to only have prices stored in one location
and for there to be correct real-time currency conversions.
Using the URL in $url I can get the product price for any quatity or
currency. Initially I was just using fopen to get the data but on
occasion the URL would fail due to timeouts (network congestion,
ecommerce server busy or failure, etc) etc. So now when a good
response has occured I store this in file in the prices directory, if
a failure occurs in the future then I can use the stored price
instead. Typically, my web pages would display prices in pounds,
dollars and euro. Traffic levels aren't very high, maybe 100 hits per
day.
Can anyone see any problems here or are there better ways of doing
this? I think a database would be overkill for this and may even cause
more reliability problems than I'm trying to fix.
MTIA

<?php
function ContractPriceFo rCurrency($cont ract, $quantity, $currency) {
$filename = 'prices/' . $contract . $quantity . $currency .
'.txt';
$url = 'http://www.xxxx.com/jsp/get_local_price .jsp?contractId ='.
$contract . '&quantity=' . $quantity . '&currency=' . $currency .
'&responseType= number';

$c = curl_init($url) ;
curl_setopt($c, CURLOPT_TIMEOUT , 1);
curl_setopt($c, CURLOPT_CONNECT TIMEOUT, 1);
curl_setopt($c, CURLOPT_RETURNT RANSFER, 1);
$price = curl_exec($c);
$price = trim($price);
curl_close($c);

// if a price has been returned then store it and use it
if ($price !== '') {
$fd = fopen($filename ,"w");
fwrite($fd, $price);
fclose($fd);
} else {
// otherwise use the stored value
$fd = fopen($filename ,"r");
$price = fread($fd, filesize($filen ame));
fclose($fd);
$price = trim($price);
}

return $price;
}
?>

--
Regards, Paul Herber, Sandrila Ltd.http://www.sandrila.co.uk/ http://www.pherber.com/
PHPs file locking is not particularly sophisticated and does not scale
well. Also, you need to consider how many files and whether the
filesystem can sensibly cope with this number - many have upper limits
on the number of files, and access times degrades badly for
significant volumes.

Definitely use a database - even if its just dbm or sqlite.

C.
Oct 6 '08 #3
corey wrote:
On Mon, 06 Oct 2008 07:07:16 -0400, Jerry Stuckle <js*******@attg lobal.net>
wrote:
>A database is definitely NOT overkill, and will cause FEWER reliability
problems.

For instance - any time you open a file for writing (or might have it
open for writing), you need to flock() the file to ensure it isn't
accessed by another script while it is being updated.


Reliability is only an issue if you dont do things right.

I WOULD like to see some timings for the difference between say
copying a text file - modifying that then updating the original after the floc()
as opposed to the (I suspect) large overhead of using a database for such simple
tasks.

Has anyone ever done any timings?

corey

Not in PHP. It's always an issue. As C indicated, file locking in PHP
isn't the greatest. And you have to ensure you NEVER access the files
unless you lock them first (and unlock them afterwards). Otherwise you
have a bug waiting to occur.

But if you're worried about performance right now - you're prematurely
optimizing.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 6 '08 #4
..oO(corey)
>On Mon, 06 Oct 2008 07:07:16 -0400, Jerry Stuckle <js*******@attg lobal.net>
wrote:
>>
A database is definitely NOT overkill, and will cause FEWER reliability
problems.

For instance - any time you open a file for writing (or might have it
open for writing), you need to flock() the file to ensure it isn't
accessed by another script while it is being updated.


Reliability is only an issue if you dont do things right.

I WOULD like to see some timings for the difference between say
copying a text file - modifying that then updating the original after the floc()
as opposed to the (I suspect) large overhead of using a database for such simple
tasks.
Connections to a MySQL database for example are quick and cheap.
I didn't benchmark it, simply because I don't consider it necessary.

Execution speed is not the only thing that matters. If I think that for
a particular task a DB would be the better and more convenient tool,
then I simply use it instead of trying to save some CPU cycles with
another, more complicated and more error-prone method.

Micha
Oct 6 '08 #5
corey wrote:
On Mon, 06 Oct 2008 10:38:47 -0400, Jerry Stuckle <js*******@attg lobal.net>
wrote:
>Not in PHP. It's always an issue. As C indicated, file locking in PHP
isn't the greatest. And you have to ensure you NEVER access the files
unless you lock them first (and unlock them afterwards). Otherwise you
have a bug waiting to occur.

If you dont use any function correctly you have a bug waiting. Thats a spurious
arguament.
Not at all. That's why there are bugs.
Are you saying that flock doesnt work (appart from the known ms-windows issues)
If so it needs fixing. If not there is no issue.
Exactly. Lots of known ms-windows issues. And while it works on Linux,
it is very easy to forget to flock() a file before reading it.
>But if you're worried about performance right now - you're prematurely
optimizing.

Not worried just curious about relative performance. If I was really concerned
about performance the last thing I'd consider would be using PHP at all. PHP is
a great scripting language but thats all. For anything much more complex it
isn't suitable.

corey

I don't worry about performance until there is a performance problem.
Instead I use best coding practices - which includes using a database
where one is called for.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 6 '08 #6
Thanks very much, guys.
--
Regards, Paul Herber, Sandrila Ltd.
http://www.sandrila.co.uk/ http://www.pherber.com/
Oct 6 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3697
by: Hugh Macdonald | last post by:
I'm calling a command from within a python script and I need to be able to both catch the output (stdout and stderr) from it and also have the PID (so that I can kill it) I can do one or other of these, but I can't find any way to do them both at the same time. So far, I've got the following options:
2
14880
by: john smith | last post by:
Hello, I am having trouble getting the parent node of an xml document using xslt. I am trying to return the node wine, but this does not return wine but the element values under wine. I thouht this would work. I am looking for the prices context and then ask for the parent node right? What am I doing wrong? Thanks in advance for your help.
0
1118
by: get.certified | last post by:
Hi there... Hope you will be doing fine. Actually, we offer Services regarding Testing of Certification of Microsoft, CISCO, ORACLE, CompTia (A+), MacroMedia, CheckPoint, and many other Certification. Abt its details..We have our own Testing Centers....U just have to send us ur detials..that is ur name, address, phone ..etc.and we will register the exam for U inthe Testing Center.....and finish the exam and pass it..and U will get the...
2
3016
by: N. Graves | last post by:
I'm planning to develop a process to import data from an external flat file to a new table automatically. As usual I'm having a hard time getting started on the solution because of the Access's flexibility. Please help me with your suggestion's about the best way accomplish this or do you know of any examples that I could review or download. Thanks in advance! Norris
15
2649
by: Colin | last post by:
I have a query that calculates the selling price of products on customer orders. Selling prices are calculated based on the average cost of the items when purchased. As I make new purchases, the product cost changes (as it should) to reflect the new average cost. However, the problem is that the selling price of previously sold items also change when new purchases are made. Keep in mind that I'm not storing any calculated values anywhere....
13
1866
by: Ørjan Langbakk | last post by:
I wanna make a file that holds the complete pricelist for a small webshop (yes, I know that a database in the background would be a lot simpler, but that is not an option today, unfortunately). I'm thinking something like creating a file that holds the productname and the price, and then just get the price from the other pages that needs it. (Typically an overview page of all the products in a category, and the spesific product pages). ...
7
4940
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i noticed when i run my stored procedure in sql studio i get a result set from my select statement and then below that i get a return value. how about when it's called from inside csharp. how do i get the return value then? thanks, rodchar
0
1678
by: rich | last post by:
Hi all, I have a fairly complex "feed" application that recieves messages from an external user-supplied API via a callback function, and attempts to forward these messages to another application via TCP/IP. To handle the different rates of communication between the two external sources, a simple FIFO circular buffer is used, the class definition for which is below. This all works fine, EXCEPT when the app receives a message from the
6
5404
by: Pete Kane | last post by:
Hi All, does anyone know a site that I can query share prices programmatically ( possibly passing in a stock symbol )?
0
1048
by: service0043 | last post by:
Some bargain prices can be found on jewelry that is sold in bulk and at auction houses on the internet. While the condition of the items might be used, some fine jewelry pieces will be sold as new. Careful shopping for the best prices might require a shopper to lower standards and choose something that was worn once and never again. In this instance, quality and price would be the factors to consider when comparison-shopping for fine...
0
8272
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8713
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8644
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8514
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2632
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1516
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.