Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Sorry if this is a stupid question but how do I write the json changes to a MySQL database via Php? From what I can understand the json is being updated on the client side via javascript.. but to save the changes do I have to send the entire json doc to server or is it possible to somehow patch the json on php side also? i want to create a google docs type autosave functionality so sending the whole json seems quite wasteful.

I'm learning web programming and this seems quite useful for what I'm doing. Any tips on how to do it in php with this?



Use the sync methods, which send, receive and merge packages of changes until all local instances of the data agree that they are caught up. These packages are intelligently created by Automerge and balance the amount of data transferred against how quickly all instances are consistent. Your PHP server app would keep track of all the local instances and pass the sends to them. You have a lot of freedom in how you implement this so long as you process the messages.

Eventually you’ll want to implement this using web sockets for performance, using a system like Laravel Broadcasting.

You can also package the total state JSON as a compact binary and store it in your server app, but you wouldn’t use that file to keep clients synced.

https://automerge.org/docs/cookbook/real-time/


I have a usecase where I think this would be useful, but it's the PHP backend producing the changes to state, not the front-end. I have a test runner that runs async on the server via a job system, and I want to sync the state to the front-end. This means I'd have to produce the diff in the backend.

What are my options for that? There's no PHP library for that, it seems. Is their goal to have someone build a PHP C extension (or FFI) to call down to their library? That seems not very fun, because it's somewhat less portable than having a pure PHP implementation (even if it might be less performant).


You’re right, there doesn’t seem to be a PHP SDK yet. This is unholy, but perhaps you could execute it in a node environment with v8js. https://github.com/phpv8/v8js

Otherwise I think you’d be looking at a headless browser in the test runner.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: