MCPcopy Index your code
hub / github.com/php/frankenphp / BenchmarkServerSuperGlobal

Function BenchmarkServerSuperGlobal

frankenphp_test.go:921–985  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

919}
920
921func BenchmarkServerSuperGlobal(b *testing.B) {
922 require.NoError(b, frankenphp.Init())
923 b.Cleanup(frankenphp.Shutdown)
924
925 cwd, _ := os.Getwd()
926 testDataDir := cwd + "/testdata/"
927
928 // Mimics headers of a request sent by Firefox to GitHub
929 headers := http.Header{}
930 headers.Add(strings.Clone("Accept"), strings.Clone("text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"))
931 headers.Add(strings.Clone("Accept-Encoding"), strings.Clone("gzip, deflate, br"))
932 headers.Add(strings.Clone("Accept-Language"), strings.Clone("fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"))
933 headers.Add(strings.Clone("Cache-Control"), strings.Clone("no-cache"))
934 headers.Add(strings.Clone("Connection"), strings.Clone("keep-alive"))
935 headers.Add(strings.Clone("Cookie"), strings.Clone("user_session=myrandomuuid; __Host-user_session_same_site=myotherrandomuuid; dotcom_user=dunglas; logged_in=yes; _foo=barbarbarbarbarbar; _device_id=anotherrandomuuid; color_mode=foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar; preferred_color_mode=light; tz=Europe%2FParis; has_recent_activity=1"))
936 headers.Add(strings.Clone("DNT"), strings.Clone("1"))
937 headers.Add(strings.Clone("Host"), strings.Clone("example.com"))
938 headers.Add(strings.Clone("Pragma"), strings.Clone("no-cache"))
939 headers.Add(strings.Clone("Sec-Fetch-Dest"), strings.Clone("document"))
940 headers.Add(strings.Clone("Sec-Fetch-Mode"), strings.Clone("navigate"))
941 headers.Add(strings.Clone("Sec-Fetch-Site"), strings.Clone("cross-site"))
942 headers.Add(strings.Clone("Sec-GPC"), strings.Clone("1"))
943 headers.Add(strings.Clone("Upgrade-Insecure-Requests"), strings.Clone("1"))
944 headers.Add(strings.Clone("User-Agent"), strings.Clone("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:122.0) Gecko/20100101 Firefox/122.0"))
945
946 // Env vars available in a typical Docker container
947 env := map[string]string{
948 "HOSTNAME": "a88e81aa22e4",
949 "PHP_INI_DIR": "/usr/local/etc/php",
950 "HOME": "/root",
951 "GODEBUG": "cgocheck=0",
952 "PHP_LDFLAGS": "-Wl,-O1 -pie",
953 "PHP_CFLAGS": "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
954 "PHP_VERSION": "8.3.2",
955 "GPG_KEYS": "1198C0117593497A5EC5C199286AF1F9897469DC C28D937575603EB4ABB725861C0779DC5C0A9DE4 AFD8691FDAEDF03BDF6E460563F15A9B715376CA",
956 "PHP_CPPFLAGS": "-fstack-protector-strong -fpic -fpie -O2 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64",
957 "PHP_ASC_URL": "https://www.php.net/distributions/php-8.3.2.tar.xz.asc",
958 "PHP_URL": "https://www.php.net/distributions/php-8.3.2.tar.xz",
959 "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
960 "XDG_CONFIG_HOME": "/config",
961 "XDG_DATA_HOME": "/data",
962 "PHPIZE_DEPS": "autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c",
963 "PWD": "/app",
964 "PHP_SHA256": "4ffa3e44afc9c590e28dc0d2d31fc61f0139f8b335f11880a121b9f9b9f0634e",
965 }
966
967 preparedEnv := frankenphp.PrepareEnv(env)
968
969 opts := []frankenphp.RequestOption{frankenphp.WithRequestDocumentRoot(testDataDir, false), frankenphp.WithRequestPreparedEnv(preparedEnv)}
970 handler := func(w http.ResponseWriter, r *http.Request) {
971 req, err := frankenphp.NewRequestWithContext(r, opts...)
972 require.NoError(b, err)
973
974 r.Header = headers
975
976 require.NoError(b, frankenphp.ServeHTTP(w, req))
977 }
978

Callers

nothing calls this directly

Calls 6

InitFunction · 0.92
PrepareEnvFunction · 0.92
WithRequestDocumentRootFunction · 0.92
WithRequestPreparedEnvFunction · 0.92
NewRequestWithContextFunction · 0.92
ServeHTTPFunction · 0.92

Tested by

no test coverage detected