Esempio n. 1
0
bool TestExtApc::test_apc_cas() {
  f_apc_store("ts", 12);
  f_apc_cas("ts", 12, 15);
  VS(f_apc_fetch("ts"), 15);
  f_apc_cas("ts", 12, 18);
  VS(f_apc_fetch("ts"), 15);
  return Count(true);
}
Esempio n. 2
0
bool TestExtApc::test_apc_clear_cache() {
  f_apc_store("ts", "TestString");
  f_apc_store("ta", CREATE_MAP2("a", 1, "b", 2));

  f_apc_clear_cache();
  VS(f_apc_fetch("ts"), false);
  VS(f_apc_fetch("ta"), false);

  VS(f_apc_fetch("ts"), false);
  VS(f_apc_fetch("ta"), false);
  return Count(true);
}
Esempio n. 3
0
String HHVM_FUNCTION(gethostbyname, const String& hostname) {
  IOStatusHelper io("gethostbyname", hostname.data());
  if (RuntimeOption::EnableDnsCache) {
    Variant success;
    Variant resolved = f_apc_fetch(hostname, ref(success),
                                   SHARED_STORE_DNS_CACHE);
    if (same(success, true)) {
      if (same(resolved, false)) {
        return hostname;
      }
      return resolved.toString();
    }
  }

  HostEnt result;
  if (!safe_gethostbyname(hostname.data(), result)) {
    if (RuntimeOption::EnableDnsCache) {
      f_apc_store(hostname, false, RuntimeOption::DnsCacheTTL,
                  SHARED_STORE_DNS_CACHE);
    }
    return hostname;
  }

  struct in_addr in;
  memcpy(&in.s_addr, *(result.hostbuf.h_addr_list), sizeof(in.s_addr));
  String ret(safe_inet_ntoa(in));
  if (RuntimeOption::EnableDnsCache) {
    f_apc_store(hostname, ret, RuntimeOption::DnsCacheTTL,
                SHARED_STORE_DNS_CACHE);
  }
  return ret;
}
Esempio n. 4
0
xmlDocPtr soap_xmlParseFile(const char *filename) {
  String cache_key("HPHP.SOAP.WSDL.");
  cache_key += filename;

  Variant content = f_apc_fetch(cache_key);
  if (same(content, false)) {
    Variant stream = File::Open(filename, "rb", CREATE_MAP1
                                ("http", CREATE_MAP1("timeout", 1000)));
    if (!same(stream, false)) {
      content = f_stream_get_contents(stream);
      if (!same(content, false)) {
        f_apc_store(cache_key, content);
      }
    }
  }

  if (!same(content, false)) {
    String scontent = content.toString();
    xmlDocPtr ret = soap_xmlParseMemory(scontent.data(), scontent.size());
    if (ret) {
      ret->URL = xmlCharStrdup(filename);
    }
    return ret;
  }
  return NULL;
}
Esempio n. 5
0
xmlDocPtr soap_xmlParseFile(const char *filename) {
  String cache_key("HPHP.SOAP.WSDL.");
  cache_key += filename;

  Variant content = f_apc_fetch(cache_key);
  if (same(content, false)) {
    Resource resource = File::Open(filename, "rb", 0, f_stream_context_create(
                make_map_array(s_http, make_map_array(s_timeout, 1000))));
    if (!resource.isNull()) {
      content = f_stream_get_contents(resource);
      if (!same(content, false)) {
        f_apc_store(cache_key, content);
      }
    }
  }

  if (!same(content, false)) {
    String scontent = content.toString();
    xmlDocPtr ret = soap_xmlParseMemory(scontent.data(), scontent.size(), false);
    if (ret) {
      ret->URL = xmlCharStrdup(filename);
    }
    return ret;
  }
  return NULL;
}
Esempio n. 6
0
bool TestExtApc::test_apc_fetch() {
  // reproducing a memory leak (3/26/09)
  f_apc_add("apcdata", CREATE_MAP2("a", "test", "b", 1)); // MapVariant
  {
    Variant apcdata = f_apc_fetch("apcdata");
    Variant c = apcdata; // bump up ref count to make a MapVariant copy
    apcdata.set("b", 3); // problem
    VS(apcdata, CREATE_MAP2("a", "test", "b", 3));
  }
  {
    Variant apcdata = f_apc_fetch("apcdata");
    apcdata += CREATE_MAP1("b", 4); // problem
    VS(apcdata, CREATE_MAP2("a", "test", "b", 1));
  }
  {
    Variant apcdata = f_apc_fetch(CREATE_VECTOR2("apcdata", "nah"));
    VS(apcdata, CREATE_MAP1("apcdata", CREATE_MAP2("a", "test", "b", 1)));
  }
  return Count(true);
}
Esempio n. 7
0
bool TestExtApc::test_apc_store() {
  Array complexMap = CREATE_MAP2("a",
                                 CREATE_MAP2("b", 1, "c",
                                             CREATE_VECTOR2("d", "e")),
                                 "f", CREATE_VECTOR3(1,2,3));
  f_apc_store("complexMap", complexMap);
  f_apc_store("ts", "TestString");
  f_apc_store("ta", CREATE_MAP2("a", 1, "b", 2));
  f_apc_store("ts", "NewValue");
  f_apc_store("ta", CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("ts"), "NewValue");
  VS(f_apc_fetch("ta"), CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("complexMap"), complexMap);

  VS(f_apc_fetch("ts"), "NewValue");
  VS(f_apc_fetch("ta"), CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("complexMap"), complexMap);

  // Make sure it doesn't change the shared value.
  Array complexMapFetched = f_apc_fetch("complexMap");
  VERIFY(complexMapFetched.exists("a"));
  complexMapFetched.set("q",0);
  VERIFY(complexMapFetched.exists("q"));
  VS(f_apc_fetch("complexMap"), complexMap);

  String tsFetched = f_apc_fetch("ts");
  VS(tsFetched, "NewValue");
  String sharedString = tsFetched;
  tsFetched.lvalAt(0) = "M";
  VS(tsFetched, "MewValue");
  VS(sharedString, "NewValue");
  VERIFY(tsFetched.get() != sharedString.get());
  VS(f_apc_fetch("ts"), "NewValue");

  return Count(true);
}
Esempio n. 8
0
bool TestExtApc::test_apc_delete() {
  f_apc_store("ts", "TestString");
  f_apc_store("ta", CREATE_MAP2("a", 1, "b", 2));
  f_apc_delete("ts");
  f_apc_delete("ta");
  VS(f_apc_fetch("ts"), false);
  VS(f_apc_fetch("ta"), false);

  VS(f_apc_fetch("ts"), false);
  VS(f_apc_fetch("ta"), false);

  f_apc_store("ts", "TestString");
  f_apc_store("ta", CREATE_MAP2("a", 1, "b", 2));
  VS(f_apc_delete(CREATE_VECTOR2("ts", "ta")), Array::Create());
  VS(f_apc_fetch("ts"), false);
  VS(f_apc_fetch("ta"), false);

  return Count(true);
}
Esempio n. 9
0
bool TestExtApc::test_apc_add() {
  f_apc_add("ts", "TestString");
  f_apc_add("ta", CREATE_MAP2("a", 1, "b", 2));
  f_apc_add("ts", "NewValue");
  f_apc_add("ta", CREATE_VECTOR1("newelement"));
  VS(f_apc_fetch("ts"), "TestString");
  VS(f_apc_fetch("ta"), CREATE_MAP2("a", 1, "b", 2));

  VS(f_apc_fetch("ts"), "TestString");
  VS(f_apc_fetch("ta"), CREATE_MAP2("a", 1, "b", 2));

  f_apc_add("texp", "TestString", 1);
  sleep(1);
  VS(f_apc_fetch("texp"), false);

  Variant ret = f_apc_store("foo", false);
  VS(ret, true);
  ret = f_apc_add("foo", false);
  VS(ret, false);
  Variant success;
  ret = f_apc_fetch("foo", ref(success));
  VS(ret, false);
  VS(success, true);
  ret = f_apc_fetch("bar", ref(success));
  VS(ret, false);
  VS(success, false);
  Variant map1= CREATE_MAP1("foo", false);
  ret = f_apc_fetch(CREATE_VECTOR1("foo"), ref(success));
  VS(ret, map1);
  ret = f_apc_fetch(CREATE_VECTOR1("bar"), ref(success));
  VS(ret, Array::Create());
  VS(success, false);
  ret = f_apc_fetch(CREATE_VECTOR2("foo", "bar"), ref(success));
  VS(ret, map1);
  VS(success, true);
  ret = f_apc_fetch(CREATE_VECTOR4("foo", "bar", "foo", "bar"), ref(success));
  VS(ret, map1);
  VS(success, true);
  return Count(true);
}