首页 \ 问答 \ PHP + cURL - 输出比预期的要早?(PHP + cURL - output is older than expected?)

PHP + cURL - 输出比预期的要早?(PHP + cURL - output is older than expected?)

我一直想弄清楚两天为什么这不起作用。 基本上我正在使用TradeMe的API,他们在这里有一个.json文件:

链接1: http//api.trademe.co.nz/v1/Listings/Latest.json

而不是耗尽API速率限制,我认为好吧......我只会为我的网络服务器编写一个脚本来抓取这个文件并将其返回给我(我当然必须在本地缓存它但我还不完全到了那里)。 我们只是说我的抓取器URL是这样的:

链接2:http:// {MY URL} /trademe/fetcher.php?url=http://api.trademe.co.nz/v1/Listings/Latest.json

事情是......链接2的cURL返回给我的不是链接1返回给我的东西! 每次我运行我的脚本(链接2)时,它总是给我一个旧版本的链接1的JSON文件(我知道它是一个旧版本,因为我查看了JSON文件中的ListingId数字)。 有时我运行链接2,它给了我一个更新的JSON,然后当我刷新脚本时,它再次给我更旧的JSON! (请注意,如果我直接在Chrome中访问链接1,它总会向我提供最新的JSON文件。我的脚本有问题吗?)

这是我的脚本:

<?php

set_time_limit(3600);

header("Content-Type: application/json");
header("Expires: on, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
$contents = curl_exec($ch);
curl_close($ch);

echo $contents;
?>

我基本上是通过jQuery的$ .getJSON来调用这个脚本。 我甚至把无缓存头文件放在我的index.php中,并放入$ .ajaxSetup({cache:false}); 但没有运气。

有任何想法吗?

(这可能会有所启发,但我还没有发现任何东西: http//developer.trademe.co.nz/api-overview/

干杯


I've been trying to figure out for two days now why this isn't working. Basically I'm playing around with TradeMe's API and they have a .json file here:

Link 1: http://api.trademe.co.nz/v1/Listings/Latest.json

Rather than exhaust the API rate limit I thought ok... I'll just write a script for my web server that grabs this file and returns it to me (I'll have to cache it locally of course but I haven't quite gotten there yet). Let's just say my fetcher URL is this:

Link 2: http://{MY URL}/trademe/fetcher.php?url=http://api.trademe.co.nz/v1/Listings/Latest.json

The thing is... what cURL returns me for link 2 is NOT what link 1 returns me! Every time I run my script (link 2) it always gives me an older version of link 1's JSON file (I know it's an older version because I look at the ListingId numbers in the JSON file). Sometimes I run link 2 and it gives me a newer JSON and then when I refresh the script it gives me the older JSON again! (Note that if I access link 1 directly in Chrome it always gives me the latest JSON file. There is something wrong with my script?)

Here's my script:

<?php

set_time_limit(3600);

header("Content-Type: application/json");
header("Expires: on, 01 Jan 1970 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/534.51.22 (KHTML, like Gecko) Version/5.1.1 Safari/534.51.22');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
$contents = curl_exec($ch);
curl_close($ch);

echo $contents;
?>

I'm basically invoking this script through jQuery's $.getJSON. I've even put the no cache headers in my index.php and also put in $.ajaxSetup({ cache: false }); but no luck.

Any ideas?

(This may shed some light but I've yet to find anything: http://developer.trademe.co.nz/api-overview/)

Cheers


原文:https://stackoverflow.com/questions/13794528
更新时间:2023-10-30 14:10

最满意答案

第一个问题:

C11 7.17.6p3

注意原子整数类型的表示不必与其对应的常规类型具有相同的大小。 它们应尽可能具有相同的大小,因为它可以减少移植现有代码所需的工作量。

第二个问题:

C11 6.7.2.4p3

[约束]

3原子类型说明符中的类型名称不应引用数组类型,函数类型,原子类型或限定类型。

volatile int是限定类型。 在违反约束部分的情况下,编译器需要输出诊断消息。 除此之外,这种结构的行为是不确定的。

第三个问题:

C11 7.17.1.p5

5在以下概要中:

  • A指的是原子类型之一。

他们期望_Atomic类型。 传入非原子变量,因此未定义行为。


First question:

C11 7.17.6p3:

NOTE The representation of atomic integer types need not have the same size as their corresponding regular types. They should have the same size whenever possible, as it eases effort required to port existing code.

Second question:

C11 6.7.2.4p3:

[Constraints]

3 The type name in an atomic type specifier shall not refer to an array type, a function type, an atomic type, or a qualified type.

volatile int is a qualified type. A shall in a constraints section is violated, therefore the compiler needs to output a diagnostics message. Beyond that, the behaviour of such a construct is undefined.

Third question:

C11 7.17.1.p5:

5 In the following synopses:

  • An A refers to one of the atomic types.

They expect an _Atomic type. You pass in a non-atomic variable, therefore undefined behaviour.

相关问答

更多
  • 通过移除/减少较不重要的节点并将一些冗余/辅助信息委托给其他方式,可以简化问题第二步产生的C11类型的混乱结构。 我为此提出了以下五步算法: 去除所有扩展的整数类型(严格符合实现的假定); 减少标准整数类型(因为它们不再分区类型); 分组结构: 标量类型与聚合类型的子树对(表示为树), 基本类型与派生类型的子树对(由彩色区域表示), 实际类型和派生的声明类型 (表示为这些的描边子区域), 字符类型 (用不同的文本颜色表示); 非标准生产的应用: 对象类型 = 标量类型 + 聚合类型 ; 补充缺失的联合类型和 ...
  • 我认为你会忽略另一种情况,相反的顺序。 考虑一个初始化的int其存储被重用来创建一个std::atomic_int 。 所有原子操作都发生在ctor完成后,因此在初始化的内存中。 但是对于现在被覆盖的int任何并发,非原子访问也必须被禁止。 (我在这里假设存储寿命已经足够,并且不起作用) 我不完全确定,因为我认为第二次访问int将无效,因为访问表达式int的类型与当时的对象类型( std::atomic )不匹配。 但是,“当时的对象类型”假定单线性时间进度不适用于多线程环境。 一般而言,C ++ ...
  • 不,这通常不便携。 calloc只保证底层对象的字节0值。 对于(可能)具有状态的类型,这不等同于初始化。 您必须使用atomic_init将对象置于有效状态。 其原因是除了基础对象之外还包含“锁定”的平台,因为它们没有实现相应的汇编程序指令。 因此,为了便于携带,您真的需要对所有未静态分配的原子对象使用ATOMIC_VAR_INIT或atomic_init 。 也就是说,我不知道任何现有的平台都需要这样的for atomic_int 。 如果您的平台的ATOMIC_INT_LOCK_FREE设置为2并且s ...
  • 如果你正在编写内核代码,你应该用C语言来完成它,然后用当前内核所需的C版本(运行gcc)来完成它。 如果你想让它接受主线(或者把它写成好像它将被接受),你应该使用Linux函数。 你也会发现他们的工作没有意外的惊喜,你将得到更好的调试帮助。 总结:使用linux的功能。 If you are writing kernel code, you should do it in C, and do it in the version of C required by the current kernel (shi ...
  • 对atomic_int限定的对象(以及atomic_int只是一个不同的写入)的操作保证具有顺序一致性。 您会在语义部分的末尾提到每个操作数。 (也许缺少对转让的提及。) 您的代码在两个地方不正确:初始化必须使用ATOMIC_VAR_INIT宏(7.17.2.1),并且memcpy未定义(大小可能不一致),尽管它可能适用于大多数体系结构。 也行 tmp = mc + 4; // Arithmetic 没有做你的评论所声称的。 这不是原子对象的算术,而是普通加法后的加载。 更有 ...
  • 有没有办法使用栅栏来推断C11中非原子操作的行为? 您使用栅栏的方式是正确的,但如果您希望能够推断程序行为,则您有责任确保在存储(1)到ready和load(1)之间存在严格的线程间修改顺序。从中。 这通常是atomic变量发挥作用的地方。 根据C11标准,您ready了数据竞争(正如您所指出的那样),未定义的行为就是您所期望的。 我的具体问题是,是否可以修复上述代码以保证打印1而不用准备好_Atomic。 (我可以准备一个不稳定的,但是在规范中没有看到任何有助于此的建议。) 符合答案的标准是“否”,因为标 ...
  • 第一个问题: C11 7.17.6p3 : 注意原子整数类型的表示不必与其对应的常规类型具有相同的大小。 它们应尽可能具有相同的大小,因为它可以减少移植现有代码所需的工作量。 第二个问题: C11 6.7.2.4p3 : [约束] 3原子类型说明符中的类型名称不应引用数组类型,函数类型,原子类型或限定类型。 volatile int是限定类型。 在违反约束部分的情况下,编译器需要输出诊断消息。 除此之外,这种结构的行为是不确定的。 第三个问题: C11 7.17.1.p5 : 5在以下概要中: A指的是原子 ...
  • 理由在N1485中找到: _Atomic关键字也可以以_Atomic(T)形式使用,其中T是一个类型,作为等同于_Atomic T的类型说明符。 因此, _Atomic(T) x, y; 声明x和y具有相同的类型,即使T是指针类型。 这允许简单的C ++ 0x与仅C ++的_Atomic(T)宏定义兼容为atomic 。 The rationale is found in N1485: The _Atomic keyword also can also be used in the form _Ato ...
  • 我认为对关键字本身的支持需要一些时间,我还没有看到一些东西。 对于图书馆支持(支持功能)而言,已有更多。 特别是我知道gcc在大多数平台的整数类型上实现原子操作__sync_...泛型函数。 我目前正致力于C11的P99合规层。 线程部分(在POSIX线程之上)已经存在,原子(使用gcc原语)很快就会完成。 这将是一个通用实现,通过宏实现所有基类型的atomic_... ,实现标准中预见的类型泛型 atomic_...函数。 它几乎就在那里,您可以在P99网站上查看第一个版本,但我仍需要几天才能完成它。 I ...
  • 我认为你的设计是正确的,除了int* refcount;的类型int* refcount; 以及指针的错误使用。 现在你没有任何东西可以指向它,所以你将通过将(不确定的)指针值传递给原子操作来调用未定义的行为。 我不明白你为什么要使用指针。 类型应该是: int refcount; 代码应该是: void value_retain(value v) { atomic_fetch_add(&v.refcount, 1); } void value_release(value v) { if ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。