{"id":13617961,"url":"https://github.com/bufferhead-code/nextjs-use-php","last_synced_at":"2025-04-14T10:30:43.428Z","repository":{"id":204338341,"uuid":"711608135","full_name":"bufferhead-code/nextjs-use-php","owner":"bufferhead-code","description":"Use PHP code right within your React / Next.js App. With \"use php\";","archived":false,"fork":false,"pushed_at":"2024-03-03T02:52:05.000Z","size":93,"stargazers_count":628,"open_issues_count":11,"forks_count":17,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-11-08T03:36:20.468Z","etag":null,"topics":["nextjs","nodejs","php","react","reactjs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bufferhead-code.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-10-29T19:22:30.000Z","updated_at":"2024-11-07T10:36:13.000Z","dependencies_parsed_at":"2023-11-02T17:01:24.329Z","dependency_job_id":"0be0b7c6-0c7f-4a36-936f-e3d2261f249a","html_url":"https://github.com/bufferhead-code/nextjs-use-php","commit_stats":null,"previous_names":["onatcer/nextjs-use-php","bufferhead-code/nextjs-use-php"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferhead-code%2Fnextjs-use-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferhead-code%2Fnextjs-use-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferhead-code%2Fnextjs-use-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bufferhead-code%2Fnextjs-use-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bufferhead-code","download_url":"https://codeload.github.com/bufferhead-code/nextjs-use-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862541,"owners_count":21173830,"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","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":["nextjs","nodejs","php","react","reactjs"],"created_at":"2024-08-01T20:01:51.567Z","updated_at":"2025-04-14T10:30:43.160Z","avatar_url":"https://github.com/bufferhead-code.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"## Next.js `use php`\n\n\u003e [!NOTE]\n\u003e Check out **solidtime - The modern Open Source Time-Tracker** at [solidtime.io](https://www.solidtime.io)\n\n\nUse PHP right inside of your Next.js project. \nJust like `use server` (not really).\n\n**You can watch how i made it [here](http://www.youtube.com/watch?v=EGOkjmyfL6E)**\n\n[![Youtube Video about how this project was made](http://img.youtube.com/vi/EGOkjmyfL6E/0.jpg)](http://www.youtube.com/watch?v=EGOkjmyfL6E \"Write PHP in Next.js/React Components\")\n\nYou can use it in React Server Components just like this: \n\n```javascript\nreturn (\n    \u003cbutton\n        formAction={async () =\u003e {\n            'use php'\n            (new PDO('mysql:host=localhost:3306;dbname=public', 'root', 'root'))\n                -\u003eprepare(\"INSERT INTO Bookmarks (slug) VALUES (?)\")\n                -\u003eexecute(array('new'));\n            }}\u003e\n        Insert Bookmark\n    \u003c/button\u003e\n)\n```\n\nAnd if you want to it can even work with React Client Components\n\n```javascript\n// actions.js\n'use server'\n\nexport async function phpHelloWorld() {\n    'use php'\n    print \"Hello from PHP\";\n}\n```\n\n```javascript\n// page.tsx\nimport {phpHelloWorld} from \"../actions\";\n```\n\n\nYes this actually works. Trust me I wish it wouldn't too. \n\n## Build \n\nYou can build the implementation by\n\n```bash\nnpm run build\nnpm run start\n```\n\nOpen [http://localhost:3000](http://localhost:3000) with your browser to see the result.\n\nIf you want to try out the Database Example, you can use the docker-compose file provided in the repository.\nafter `docker-compose up -d` you need to create the database and table you want to insert into manually.\n\n## Roadmap (Things that should be fixed but realistically it will never happen)\n\n- [ ] There is a probably a way to fix that nasty preprocess step with [SWC Plugins]( https://swc.rs/docs/plugin/ecmascript/getting-started) which are still in Beta with Next.js and also I think they will switch builder anyways soon so what's the point really? But hey if anyone wants to do it feel free.\n- [ ] I guess there is some hacky way to make props binding possible.\n\n## Credits\n\nCheck out the original implementations by elnardu for C and Rust:\n\n* https://github.com/elnardu/react-use-c\n* https://github.com/elnardu/react-use-rust\n\n## Disclaimer\n\n*I hope I don't have to say this but: If you even in the slightest consider to use this in any application at all you are an absolute madperson and and should be locked out of the internet for the rest of your life, I hope you find some other fun activity, maybe gardening or woodwork.* \n\n## Self-Promo\n\nIf you enjoyed this project and want to see more silly web development projects, you can follow me on [Twitter](https://twitter.com/bufferhead_), [Bluesky](https://bsky.app/profile/bufferhead.bsky.social) and [Youtube](https://www.youtube.com/@bufferhead_). \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferhead-code%2Fnextjs-use-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbufferhead-code%2Fnextjs-use-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbufferhead-code%2Fnextjs-use-php/lists"}