Back to Question Center
0

Kaddamar da Wasanni tare da Ci gaba da kuma PHP: Yaya Yarda Da Su?            Game da bunkasa Game tare da Ci gaba da PHP: Yaya Yada Tambaya? APIsSecurityDatabasePerformance & Cikewar tsaftacewa

1 answers:
Gabatarwa Game tare da Ci gaba da PHP: Ta Yaya Ya dace?

Tsara Ayyuka tare da PHP da ReactJS

  • Ci gaban wasanni tare da Nemo da kuma PHP: Yaya Yada Kashe?
  • Hanyar da aka tsara Game da Jirgi tare da Riga, PHP, da Yanar Gizo

Ga wani kyakkyawan halayen, gabatarwa mai zurfi don Gyarawa, ba za ka iya ci gaba da ci gaba da ƙwaƙwalwar Wes Bos ba. Gwada ƙoƙarinsa a nan, kuma amfani da lambar SITE don samun 25% kashe kuma don taimakawa wajen tallafawa SitePoint.

"Ina so in yi wasan kwaikwayo mai yawa, tattalin arziki. Wani abu kamar Stardew Semalt, amma ba tare da wani ɓangare na aboki da tattalin arziki mai kunnawa ba. "

Na fara tunani game da wannan lokacin da na yanke shawarar gwadawa da gina wasan ta amfani da PHP da Semalt - politicas de privacidad para sitios web. Matsalar ita ce, ban san komai game da matsalolin wasanni masu yawa ba, ko yadda za mu yi tunani game da aiwatar da tattalin arzikin wasanni.

Kaddamar da Wasanni tare da Ci gaba da kuma PHP: Yaya Yarda Da Su?Game da bunkasa Game tare da Ci gaba da PHP: Yaya Yada Tambaya?
APIsSecurityDatabasePerformance & ScalingDevelopment Semalt

Ban tabbata ko na san isa game da Semalt don tabbatar da amfani da shi ba. Ina nufin, ingancin farko - inda na mayar da hankali ga uwar garke da kuma yanayin tattalin arziki na wasan - ya dace daidai da Semalt. Amma yaya game da lokacin da na fara yin fasalin aikin gona / hulda? Ina ƙaunar ra'ayin gina gine-gine na samfur a tsarin tsarin tattalin arziki.

Shawarar Kwarewa

Na taba kallon kalma ta dead_lugosi, inda ta bayyana gina wani wasa mai mahimmanci a cikin PHP. Margaret ya karfafa ni, kuma wannan magana shine ɗaya daga cikin abubuwan da suka kai ni rubuta wani littafi game da ci gaban JS. Na zama da niyyar rubuta game da kwarewa. Sauraran wasu zasu iya koya daga kuskuren a wannan yanayin, ma.


Ana iya samun lambar don wannan bangare a: github. com / assertchris-tutorials / wuri-making-games / tree / part-1. Na gwada shi tare da PHP 7. 1 da kuma a cikin kwanan nan Google Chrome.


Kafa Ƙarshen Ƙarshe

Abu na farko da na neme shi shine jagorancin gina tattalin arziki mai yawa. Na sami wata kyakkyawar matsala mai tsayi wanda aka yi bayani game da abubuwa daban-daban don tunani. Na yi kusan rabin cikin ciki kafin in gane cewa na fara daga wuri mara kyau.

"Na farko abu na farko: Ina bukatan uwar garken PHP. Zan samu batu na React abokan ciniki, don haka ina son wani abu mai girma mai karfin gaske (watakila ma Semalt). Kuma yana buƙatar zama m: abubuwa dole ne ya faru ko da a lokacin da 'yan wasan ba su kusa ba. "

Na je aiki aiki da async PHP uwar garken - don rike high concurrency da goyon bayan Semalt. Na kara da aikin da nake da shi a kwanan nan tare da masu amfani da PHP don yin tsabta, kuma na sanya mahimman ra'ayoyin farko.

Daga saita. pre :

     Kamfanin rundunar = sabon Mai watsa shiri na Aerys   ;$ host-> bayyana ("*", 8080);$ host-> amfani ($ router = Aerys \ router   );$ host-> amfani ($ root = Aerys \ tushen (."/ jama'a"));$ web = tsari. "/ hanyoyi / yanar gizo."$ yanar gizo ($ router);$ api = tsari. "/ hanyoyi / api na farko";$ api ($ rozer);    

Na yanke shawarar yin amfani da Semalt don aikace-aikacen HTTP da WebSocket na aikace-aikacen. Wannan lamarin ya bambanta da kullun Semalt, amma saboda haka ina da kyakkyawan ra'ayin game da abin da nake bukata.

Hanyar da aka saba amfani dashi don yin amfani da wani shiri mai tsafta shine amfani da umurnin kamar haka:

   mai sayarwa / bin / aerys -d -c. php    

Ya ƙaddamar da lamba mai yawa don ci gaba da maimaitawa, kuma bai kula da gaskiyar cewa ina so in yi amfani da madaidaiciyar PHP ba. Na ƙirƙiri fayil ɗin caji. php :

     dawo da tsariTa bincika (__ DIR__. / / Config. Pre ");    

Daga nan sai na shigar da mutanena. Wannan shi ne daga mawaki. json :

     "buƙatar": {"amphp / aerys": "dev-amp_v2","amphp / layi daya": "dev-master","Liga / akwati": "^ 2 2","layi / faranti": "^ 3.3","pre / short-closures": "^ 0 4. 4."},"bukatar-dev": {"phpunit / phpunit": "^ 6. 0"},    

Ina so in yi amfani da amfalle , don motsa lambar cirewa daga uwar garken async, amma ba zai shigar da tagulla amphp / aerys ba. Abin da ya sa na tafi tare da dev-amp_v2 reshe.

Na tsammanin zai zama kyakkyawan ra'ayi na haɗa da wasu nau'in samfurin samfurin da mai bada sabis. Na opted for PHP jerin nau'i na kowanne. A ƙarshe na ƙara pre / short-closures , duka biyu don rike da daidaituwa ta al'ada a saita. kafin da kuma gajeren gajere na shirya don amfani bayan .

Sa'an nan kuma na shirya game da hanyoyin samar da hanyoyi. Daga hanyoyi / yanar gizo. pre :

     yi amfani da na'ura mai amfani da na'ura;amfani da App \ Action & HomeAction;dawo (Mai ba da hanya tsakanin hanyoyin sadarwa $ roji) => {$ router-> hanya ("GET", "/", sabon HomeAction);};    

Kuma, daga hanyoyi / api. pre :

     yi amfani da na'ura mai amfani da na'ura;amfani da App \ Action \ Api \ HomeAction;dawo (Mai ba da hanya tsakanin hanyoyin sadarwa $ roji) => {$ router-> hanya ("GET", "/ api", sabon HomeAction);};    

Ko da yake hanyoyi masu sauƙi, waɗannan sun taimake ni in gwada lambar a saiti. pre . Na yanke shawarar yin wa annan hanyoyi fayilolin dawo da kullun, saboda haka zan iya sanya su tarar da $ router , wanda za su iya ƙara hanyoyi. A ƙarshe, na ƙirƙiri abubuwa biyu (irin wannan).

Daga app / Actions / HomeAction. pre :

     Aikace-aikacen aiki na yanki;Yi amfani da Aikace-aikacen Aerys;Yi amfani da Aerys \ Response;Makarantar HomeAction{Ayyukan jama'a na aiki (Request request request,Amsar $ amsa){$ response-> Ƙarshen ("sannu duniya");}}    

Ɗaya daga cikin taɓawa ta ƙarshe ita ce don ƙara rubutun gajerun hanyoyi, don ƙaddamar da ƙwaƙwalwa da kuma samfurori na kamfanonin Semalt.

Daga mawaki. json :

     "rubutun": {"dev": "mai sayarwa / bin / aerys -d -c loader. php","prod": "mai sayarwa / bin / aerys -c loader. php"},"Saitin": {"lokaci-lokaci": 0},    

Tare da wannan duka, zan iya juya sabon sabar, kuma ziyarci http: // 127. 0. 0. 1: 8080 kawai ta hanyar bugawa:

   mawallafi dev    

Kafa Ƙarshen Ƙarshe

"Na'am, yanzu ina da ƙungiyar PHP ta abubuwan da suka shafi zaman lafiya; Ta yaya zan gina fayilolin ReactJS? Zai yiwu zan iya amfani da Laravel Mix . ? "

Ba na da sha'awar samar da sababbin sassan ginawa, kuma an sake gina Mix don yin aiki sosai akan ayyukan Lara Lara. Tsasawa ya kasance mai sauƙin sauƙaƙe da kuma mikawa, shi ya fi dacewa ViewJS ta tsoho.

Abu na farko da zan yi shine shigar da wasu ƙididdigar NPM. Daga kunshin. json :

     "ƙaddarawa": {"babel-preset-react": "^ 6 23. 0", ""bootstrap-sass": "^ 3. 3. 7","jquery": "^ 3 1. 1.", ""Laravel-Mix": "^ 0 7. 7.", ""amsa": "^ 15 4. 4.", ""amsa-dom": "^ 15 4. 4.", ""shafin yanar gizo": "^ 2 2. 1"},    

Mix amfani da Webpack zuwa preprocess da dam JS da CSS fayiloli. Har ila yau, ina buƙatar shigar da Gidaje da kuma ɗakunan karatu na Babel don gina fayiloli jsx . A ƙarshe, na kara da fayilolin Bootstrap, don bit na tsoho salo.

Mix ta atomatik loaded wani al'ada tsari sanyi, don haka sai na kara da cewa wadannan. Daga shafin yanar gizon. Mix. js :

     bari mix = buƙatar ("mixer-mix")// kaddamar da shirye-shiryen babel don fayilolin jsxMix. shafin yanar gizoConfig ({"ƙungiya": {"dokokin": [{"gwaji": / jsx $ /,"ware": / (node_modules) /,"loader": "babel-loader" + mix. saiti. SetPublicPath ("jama'a")Mix. js ("dukiya / js / app. jsx", "jama'a / js / app. js")Mix. sass ("dukiya / scss / app. scss", "jama'a / css / app. css")Mix. version       

Ina buƙatar gaya Ma'anar abinda za a yi tare da fayiloli jsx , don haka sai na kara da irin wannan tsari wanda za'a iya sa a cikin . babelrc . Na shirya don samun jigilar JS da CSS a cikin aikace-aikace daban-daban na bits da bobs.

Lura: Yanayin da ke gaba na Mix za su shiga jirgi tare da goyon baya don gina gine-gine na ReactJS. Lokacin da wannan ya faru, da Mix. Shafin yanar gizoConfig za a iya cire lambar.

Har yanzu, Na ƙirƙiri wasu rubutattun gajerun hanyoyi, don ajiyewa a rubutu mai tsanani. Daga kunshin. json :

     "rubutun": {"dev": "$ npm_package_config_webpack","kallo": "$ npm_package_config_webpack -w","prod": "$ npm_package_config_webpack -p"},"Saitin": {"shafin yanar gizon yanar gizo": "shafin yanar gizon yanar gizo - progress --i-modules --config = node_modules / laravel-mix / saitin / shafin yanar gizo.},    

Duk rubutun uku sunyi amfani da umarnin yanar gizon Webpack, amma sun saba da abin da suka aikata fiye da haka. dev ya gina wani ɓangaren debug daga cikin fayilolin JS da CSS. Hanyoyin -w ya fara mai kula da Webpack (don haka za'a iya sake gina sassan). Canjin -p ya ba da damar samar da samfurori na kamfanonin.

Tun lokacin da nake amfani da kundin tsarin bugawa, Ina buƙatar hanyar yin amfani da fayiloli kamar / js / app. 60795d5b3951178abba1. js ba tare da sanin hash ba. Na lura Mix yana son ƙirƙirar fayil mai kyau, don haka sai na yi aiki na taimakawa don nema shi. Daga mataimakan. pre :

     yi amfani da Amp \ Coroutine;aikin aiki ($ hanyar) {$ generator =    => {$ bayyana = samar da amfanar fayil na Amp \ "(". "/ jama'a / mix-manifest. json");$ bayyana = json_decode ($ bayyanar, gaskiya);idan (farko ($ bayyana [$ hanyar])) {dawo $ bayyana [$ hanyar];}jefa sabon Sakamakon ("{$ hanya} ba a samo ba");};dawo sabon Coroutine ($ generator   );}    

Aerys sun san yadda za su rike alkawuran idan suka zo cikin $ val = samar da alkawarin alkawarin , don haka sai na yi amfani da Amfani da Amfani da Amp. Lokacin da aka karanta fayil din kuma an tsara shi, zan iya nema hanyar hanyar daidaitawa. Na gyara HomeAction . Daga app / Actions / HomeAction. pre :

     Ayyukan jama'a __cvoke (Bada takardar neman kuɗi,Amsar $ amsa){$ hanya = Mix mix ("/ js / app. js");$ adireshin-> ƙare (" 
March 1, 2018