[{"data":1,"prerenderedAt":194},["ShallowReactive",2],{"\u002Fzend-hacking":3},{"id":4,"title":5,"body":6,"createdAt":181,"description":12,"draft":182,"extension":183,"image":184,"mastodonThread":184,"meta":185,"navigation":186,"path":187,"seo":188,"stem":189,"tags":190,"updatedAt":192,"__hash__":193},"content\u002FZend Hacking.md","Zend_Hacking",{"type":7,"value":8,"toc":175},"minimark",[9,13,16,19,24,38,41,62,81,86,108,112,122,126,129,137,140,143,146,149,152,155,158,172],[10,11,12],"p",{},"Zend (PHP) isn't really documented all that much, besides the source itself. It looks like once you understand the beast the documentation wouldn't be all that necessary -- silly I know, but that's the way it looks.",[10,14,15],{},"Well I'm going to try writing a Zend extension. So I'm having a look at APD and eAccelerator and Zend itself to see what is going on in there. They make it relatively easy to do an extension, with magical build scripts and such.",[10,17,18],{},"Tips \u002F Documentation recommendations are appreciated if anyone out there knows of some magical wiki in the sky diagraming and analyzing all the components.",[20,21,23],"h2",{"id":22},"goal","Goal",[10,25,26,27,32,33,37],{},"Well for anyone who doesn't know, I am obsessed with ",[28,29,31],"a",{"href":30},"\u002Fcontinuation-based-web-programming","Continuation-based Web Programming",". To this end I've created ",[28,34,36],{"href":35},"\u002Fcontize","Contize"," for Perl and PHP (which is just a hack, not really continuations). I've examined cpan:Coro::Cont to see if I can get these continuations to serialize, but even the author of that module things it isn't possible. At work I'm doing all of this in PHP, so this is an experiment to see if I can hack up Zend to do (serializable) continuations.",[10,39,40],{},"So I want a few functions:",[42,43,44,53,56,59],"ul",{},[45,46,47,48],"li",{},"contize($function_name) - Indicate a function\u002Fobject that I want to be a continuation\n",[42,49,50],{},[45,51,52],{},"or perhaps call($func_name, $arg_array) - like callcc",[45,54,55],{},"yield $val - Indicate where the continuation exits",[45,57,58],{},"$serial = serialize_continuation($function_name) - Serialize the continuation",[45,60,61],{},"unserialize_continuation($serial) - De-Serialize the continuation",[10,63,64,65,68,69,71,72,74,75,77,78,80],{},"So maybe like:",[66,67],"br",{},"\nmake_continuation(\"func\");",[66,70],{},"\n$result = func($p1, $p2, ...);",[66,73],{},"\n$s = serialize_continuation(\"func\");",[66,76],{},"\nunserialize_continuation($s);",[66,79],{},"\nfunc($p1, $p2, ...);",[82,83,85],"h1",{"id":84},"","...",[10,87,88,89,91,92,94,95,91,97,99,100,91,102,104,105,107],{},"function func($p1, $p2, $p3) {",[66,90],{},"\n# stuff",[66,93],{},"\nyield $result1;",[66,96],{},[66,98],{},"\nyield $result2;",[66,101],{},[66,103],{},"\nreturn $result3 ;",[66,106],{},"\n}",[20,109,111],{"id":110},"files","Files",[42,113,114],{},[45,115,116,121],{},[28,117,118],{"href":118,"rel":119},"http:\u002F\u002Flxr.php.net\u002Fsource\u002FZendEngine2\u002Fzend_globals.h",[120],"nofollow"," - especially see the Zend Executor Globals (and maybe the compiler gloabals too)",[20,123,125],{"id":124},"notes","Notes",[10,127,128],{},"OK, I have a basic thing going now. Just ripped stuff out of various examples and grabbed call_user_func_array.",[42,130,131,134],{},[45,132,133],{},"hold the current status of a call",[45,135,136],{},"hold the return state, or a set of pointers, so we can jump directly out of a func",[10,138,139],{},"call -- save the current state for a later yield. Initialize\u002Frestore the continuation state for the function we're calling",[10,141,142],{},"yield -- save all the state between the call and here. restore the state of the initial call, pretending the parameter to yield was returned from the function like it exited normally",[10,144,145],{},"So we need two storage areas -- one for current state and one for continuation state. The current state might end up being pointers or something. both should be stacks so that we can have nested continuations.",[10,147,148],{},"Should the continuation state be stored by-name of the function?",[10,150,151],{},"I should look at other documentation on partial continuations to see if there is a standard naming scheme for all of this.",[153,154],"hr",{},[10,156,157],{},"OK, here's an idea -- we abuse the exception handler framework a bit. So the code pretends to be like this:",[10,159,160,161,163,164,166,167,169,170,107],{},"try {",[66,162],{},"\nccall('func',$p1,$p2,...);",[66,165],{},"\n} catch(cont) {",[66,168],{},"\n\u002F\u002F Do nothing, just continue",[66,171],{},[10,173,174],{},"And I'm interested in this because it is easy enough to save the current state stuff, but not so easy to escape during the middle of the computation.",{"title":84,"searchDepth":176,"depth":176,"links":177},2,[178,179,180],{"id":22,"depth":176,"text":23},{"id":110,"depth":176,"text":111},{"id":124,"depth":176,"text":125},"2005-06-11T18:53-04:00",false,"md",null,{},true,"\u002Fzend-hacking",{"title":5,"description":12},"Zend Hacking",[191],"project","2005-06-17T17:12-04:00","WhEjqMKnDX1LIDG-OEU30nm1GybR2eQfTlA60sOtoyc",1778988315562]