同步。库存数据与活货数据
我想将我的应用程序数据(库存)与实时数据同步。我正在使用 Yahoo API .. 这是我的代码 ..
// $companyInfo ; holds company information like symbol
foreach($companyInfo as $singleCompany)
{
$feedUrl = 'http://finance.yahoo.com/d/quotes.csv?s='.$singleCompany['Company']['Symbol'].'&f=l1c6gho&e=.csv';
$handle = fopen($feedUrl, "r");
$liveCompanyData = fgetcsv($handle);
if(!empty($liveCompanyData) && isset($liveCompanyData))
{
/*** here I parse data n save it in db ***/
}
fclose($handle);
}
上面的代码适用于小数据集(即大约 30 条记录),对于长记录集,它会提示我超出了最大执行时间 60 秒在......
我该怎么办?
注意:我正在使用 cakephp 框架。
I want to synchronize my app data ( stock ) with that of live ones . I am using Yahoo API .. Here is my code ..
// $companyInfo ; holds company information like symbol
foreach($companyInfo as $singleCompany)
{
$feedUrl = 'http://finance.yahoo.com/d/quotes.csv?s='.$singleCompany['Company']['Symbol'].'&f=l1c6gho&e=.csv';
$handle = fopen($feedUrl, "r");
$liveCompanyData = fgetcsv($handle);
if(!empty($liveCompanyData) && isset($liveCompanyData))
{
/*** here I parse data n save it in db ***/
}
fclose($handle);
}
Above code will work for small set of data (i.e for records 30 approx ), and for long set of records it will prompt me Maximum execution time of 60 seconds exceeded in .....
how can I do that ?
NOTE : I am using cakephp framework.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
set_time_limit
函数:但是,如果 PHP 处于安全模式(请参阅
if
),它将不起作用。在这种情况下,您必须关闭安全模式,或限制脚本执行时间 - 例如,一次仅处理一家公司,并为每个公司单独执行脚本。既然你说你正在使用 CakePHP,我假设你的代码在用户请求的脚本中运行 - 这不是最好的设计,因为它实际上是一个服务脚本。最好将其作为 cron 作业运行(
php -f your_script.php
) - 在这种情况下,使用不同的 php 配置文件(通常为 /etc/php5/cli/php.ini) ,如果您有访问/权限来编辑它 - 更改 max_execution_time 参数 (它只会影响 php-cli 脚本)。You may use
set_time_limit
function:However, it will not work if PHP is in safe mode (see that
if
). In that case, you've got to either turn off safe mode, or limit script execution time - for example by processing only one company at a time, and executing your script separately for each company.And since you say you're using CakePHP, I assume that your code runs in user-requested script - which is not the best design, as it is actually a service script. It would be better to run it as a cron job (
php -f your_script.php
) - in this case, different php configuration file is used (/etc/php5/cli/php.ini usually), and if you have access/privileges to edit it - change max_execution_time parameter in it (it will affect only php-cli scripts).