{"id":15021904,"url":"https://github.com/php/pecl-php-ffi","last_synced_at":"2025-10-14T05:32:27.101Z","repository":{"id":141192529,"uuid":"76208765","full_name":"php/pecl-php-ffi","owner":"php","description":"Foreign Function Interface","archived":false,"fork":false,"pushed_at":"2016-12-12T00:24:31.000Z","size":187,"stargazers_count":11,"open_issues_count":0,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-09-26T00:41:30.836Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pecl.php.net/package/ffi","language":"C","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-12-12T00:23:11.000Z","updated_at":"2023-09-04T06:40:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"52d170a2-64ea-47be-a97a-ba951b1e8089","html_url":"https://github.com/php/pecl-php-ffi","commit_stats":{"total_commits":60,"total_committers":10,"mean_commits":6.0,"dds":0.3666666666666667,"last_synced_commit":"b47a2cf79c0e3c780c3e5864f1ca4bc9de61dc82"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/php/pecl-php-ffi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-php-ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-php-ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-php-ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-php-ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php","download_url":"https://codeload.github.com/php/pecl-php-ffi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php%2Fpecl-php-ffi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018011,"owners_count":26086235,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T19:57:12.327Z","updated_at":"2025-10-14T05:32:27.079Z","avatar_url":"https://github.com/php.png","language":"C","readme":"$Id$\n\nUsage:\n\nFirst you need to declare the functions and types that you will be using:\n\n$win32_idl \u003c\u003c\u003cEOD\n[lib='kernel32.dll'] DWORD GetTickCount();\n[lib='user32.dll'] int MessageBoxA(int handle, char *text, char *caption, int type);\nEOD;\n\nThen bind those into an ffi context:\n\n$ffi = new ffi($win32_idl);\n\nAnd then use it:\n\n$count = $ffi-\u003eGetTickCount();\necho $ffi-\u003eMessageBoxA(0, \"The tick count is \" . $count, \"Ticky Ticky\", 1);\n\nStructures:\n===========\n\nYou can declare structures in your ffi IDL using C style syntax.\nStructure support is read-only for the moment.  You can pass structures\nto functions and return them (these two examples work on linux):\n\nPassing structs:\n\n\u003c?php\n\n$ffi = new ffi(\u003c\u003c\u003cEOD\nstruct timeval {\n\tlong tv_sec;\n\tlong tv_usec;\n};\nstruct timezone {\n\tint  tz_minuteswest;\n\tint  tz_dsttime;\n};\n[lib='libc.so.6'] int gettimeofday(struct timeval *tv, struct timezone *tz);\nEOD\n);\n\n$tv = new ffi_struct($ffi, \"timeval\");\n$tz = new ffi_struct($ffi, \"timezone\");\nvar_dump( $ffi-\u003egettimeofday($tv, $tz) );\nprintf(\"tv_sec=%d tv_usec=%d\\n\", $tv-\u003etv_sec, $tv-\u003etv_usec);\n?\u003e\n\nReturning Structs:\n\n\u003c?php\n\n$ffi = new ffi(\u003c\u003c\u003cEOD\nstruct hostent {\n  \tchar *h_name;\n    char **h_aliases;\n\tint h_addrtype;\n\tint h_length;\n\tchar **h_addr_list;\n};\n[lib='libc.so.6'] struct hostent *gethostbyname(char *name);\nEOD\n);\n\n$he = $ffi-\u003egethostbyname(\"localhost\");\nprintf(\"h_length=%d h_name=%s\\n\", $he-\u003eh_length, $he-\u003eh_name);\n?\u003e\n\nTips:\n\nFor functions that expect to copy/store memory into a buffer, use\nstr_repeat() to \"allocate\" room for that buffer.\n\nvim:tw=78:et\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp%2Fpecl-php-ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp%2Fpecl-php-ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp%2Fpecl-php-ffi/lists"}