-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDEV.txt
More file actions
executable file
·526 lines (390 loc) · 12.2 KB
/
DEV.txt
File metadata and controls
executable file
·526 lines (390 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
Add Library:
------------
composer require phpstreamserver/scheduler
Sample Data (DB: employees):
https://dev.mysql.com/doc/employee/en/employees-installation.html
------------
https://github.com/datacharmer/test_db
Build Directory structure :
BASIC
---------------------------
mkdir ./cron &&
mkdir -p ./ffi/source &&
mkdir ./ffi/lib &&
mkdir ./public
Build Core Directory structure :
FRAMEWORK
--------------------------------
mkdir ./config &&
mkdir -p ./app/Core/Database &&
mkdir -p ./app/Core/Support &&
mkdir -p ./app/Core/Auth &&
mkdir -p ./app/Core/Events &&
mkdir -p ./app/Core/Http &&
mkdir -p ./app/Core/FFI &&
mkdir ./app/Helpers &&
mkdir ./app/Models &&
mkdir ./app/Structs &&
mkdir ./app/Data &&
mkdir ./app/Listeners &&
mkdir ./static &&
mkdir -p ./storage/database &&
mkdir -p ./storage/framework &&
mkdir -p ./storage/logs &&
mkdir -p ./views/partial &&
mkdir -p ./views/elements &&
mkdir -p ./views/error
######################################################
BUILD APP
######################################################
Migrations Files:
----------------
storage/database/migrations/mysql/*.sql
Seeders:
--------
storage/database/seeders/mysql/*.sql
Build shared Library:
GO
---------------------
go build -buildmode=c-shared -o ./ffi/lib/concurrency.so ./ffi/source/concurrency.go
go build -buildmode=c-shared -o ./ffi/lib/fibonacci.so ./ffi/source/fibonacci.go
Build shared Library:
RUST
---------------------
cd ffi/source/rust_curl
cargo build --release
cp target/release/librust_curl_ffi.so ../../lib/librust_curl_ffi.so
######################################################
LOGGING
######################################################
Test - Log:
-----------
php ./cron/test.php >> ./cron_log.txt
Main Error Log:
(Auto Create)
---------------
app : storage/logs/app-error.log
cron : storage/logs/worker-error.log
DB : storage/logs/error_DB.log
Encrypt : storage/logs/error_ENCRYPTION.log
Queue : storage/logs/error_RabbitFFI.log
Events : storage/logs/error_EventLib.log
######################################################
RUN APP
######################################################
Generate new KEY:
----------------
App Key | Api Key | JWT Secret
$secret = generateRandomString(64, false);
dd($secret);
SodiumAuth:
dd(bin2hex(random_bytes(32)));
or
php -r "echo bin2hex(random_bytes(32)).PHP_EOL;"
FrankenPHP:
# Install FrankenPHP on Linux or macOS
curl https://frankenphp.dev/install.sh | sh
-----------
Check Version:
frankenphp version
Validate Config(Caddyfile):
frankenphp validate
Add Extensions(Linux-Ubuntu)
----------------------------
sudo apt update
sudo apt install php-zts-pdo php-zts-pdo-mysql php-zts-pdo-sqlite
sudo apt install php-zts-ffi
sudo apt install php-zts-redis
RUN - With Frankenphp (terminal 1)
http://localhost:8000
---------------------
frankenphp stop
frankenphp run
RUN - Worker (terminal 2):
-------------------------
php worker.php start
frankenphp php-cli worker.php start
frankenphp php-cli worker.php stop
RUN - with composer:
--------------------
composer start:all
composer stop:all
Optional without FrankenPHP
RUN - Web (new terminal):
----------------------
php -S localhost:8000 -t public/
OR Publish to network:
---------------------
php -S 0.0.0.0:8000 -t public/
Update composer :
-----------------
composer dump-autoload -o
composer du -o
// Tmp Cleaner
php cron/cleanTmp.php
######################################################
FIXING and DEBUGGING
######################################################
Fixing
PHP Warning: cli_set_process_title(): cli_set_process_title had an error: Not initialized correctly
--------------------------------------
vendor/phpstreamserver/core/src/Internal/MasterProcess.php - line 163
Replace : \cli_set_process_title TO @cli_set_process_title
GIT Clone from branch :
-----------------------
git clone -b <branch_name> --single-branch <repository_url>
// Force adding file
git add -f app/Structs/Dashboard/DashboardStruct.php
// Log-Debug :
--------------
write_log($this->getSQL(), 'Database.Model.execQuery.getSQL', 'debug', 'debug-model.log');
######################################################
TESTING - CURL
######################################################
// Test-Curl JSON :
-------------------
curl --request GET \
--url http://localhost:8000/dashboard \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=' \
--data '{
"title" : "JSON data <script>document.print</script>",
"tag_html" : {
"div" : "<div onclick='\''submitError()'\''>Submit</div>"
},
"page": "1",
"offset": "0",
"limit": 10000
}'
// POST - Validation errors
curl --request POST \
--url http://localhost:8000/dashboard \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=' \
--data '{
"title" : "JSON data <script>document.print</script>",
"tag_html" : {
"div" : "<div onclick='\''submitError()'\''>Submit</div>"
},
"age": "18",
"username": "lutvi",
"email": "lutvi-demo.local",
"website": "http://demo.local:8000/dashboard/"
}'
// POST - Valid Stuct
curl --request POST \
--url http://localhost:8000/dashboard \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=' \
--data '{
"title" : "JSON data <script>document.print</script>",
"tag_html" : {
"div" : "<div onclick='\''submitError()'\''>Submit</div>"
},
"age": "18",
"username": "lutvi",
"email": "lutvi@demo.local",
"website": "http://demo.local:8000/dashboard/"
}'
######################################################
BUILD FFI - LIB
######################################################
crawler.go
===========
$ cd ffi/source/crawler
$ go mod init mycrawler
$ go get github.com/PuerkitoBio/goquery
$ go mod tidy
$ go run crawler.go
$ go build -o ../../lib/crawler.so -buildmode=c-shared ./crawler.go
$ chmod +x ./ffi/lib/crawler.so
$ file ./ffi/lib/crawler.so
php cron/test.php >> ./storage/logs/test.txt
php cron/crawler.php >> ./storage/logs/crawler-out.txt
php cron/crawler.php > ./storage/logs/crawler-out.txt
mq.go (Queue FFI)
=================
cd ffi/source/mq
go mod init mq
go mod tidy
go build -o ../../lib/mq.so -buildmode=c-shared ./mq.go
PHP-Testing
-----------
Consumer : php cron/queue-consumer.php
Send Testing : php cron/queue.php
Sanitize:
---------
cd ffi/source/sanitize
go mod init phpffi.lutvi/sanitize
go mod tidy
go build -o ../../lib/sanitize.so -buildmode=c-shared ./sanitize.go
go build -buildmode=c-shared -o ./ffi/lib/sanitize.so ./ffi/source/sanitize/sanitize.go
Validator:
---------
cd ffi/source/dynamic_validate
go mod init phpffi.lutvi/dynamic_validate
go mod tidy
go build -o ../../lib/dynamic_validate.so -buildmode=c-shared ./dynamic_validate.go
go build -buildmode=c-shared -o ./ffi/lib/dynamic_validate.so ./ffi/source/dynamic_validate/dynamic_validate.go
Bulk_Data:
----------
cd ffi/source/bulk_data
go mod init bulk_data
go mod tidy
go build -buildmode=c-shared -o ../../lib/bulk_data.so ./bulk_data.go
OR ---
go build -buildmode=c-shared -o ./ffi/lib/bulk_data.so ./ffi/source/bulk_data/bulk_data.go
php cron/bulkData.php
php cron/searchBulkData.php
curlgo.go (CURL with Go - FFI)
==============================
cd ffi/source/curlgo
go mod init curlgo
go mod tidy
go build -o ../../lib/curlgo.so -buildmode=c-shared ./curlgo.go
PHP-Testing
-----------
Curl-Go : php cron/curlGo.php
Curl - Rust (FFI)
cargo clean (menghapus semua cache build)
==================
cd ffi/source/rust_curl
cargo build --release
cp target/release/librust_curl_ffi.so ../../lib/librust_curl_ffi.so
PHP-Testing
-----------
Curl-Rust : php cron/curlRust.php
DataEngine(Filter) - Rust (FFI)
cargo clean (menghapus semua cache build)
==================
cd ffi/source/data_engine
cargo test
cargo build --release
cp target/release/libdata_engine.so ../../lib/libdata_engine.so
PHP-Testing
-----------
Data Filter-Rust : php cron/DataEngine.php
Protobuf(Serial) - Rust (FFI)
https://protobuf.dev/installation/
cargo clean (menghapus semua cache build)
==================
protoc --version
cd ffi/source/rust_protobuf/rust-lib
cargo test
cargo build --release
cp ../target/release/librust_protobuf.so ../../../lib/librust_protobuf.so
Web-Testing
-----------
Protobuf Serialize-Rust : http://localhost:8000/testing
Event - Listener:
=================
// Migarte table
storage/database/migrations/mysql/event_queue.sql
// Consume Queue
php cron/queue-consumer.php
// Run Listener and Dispact Event on separated terminals
php cron/event-listener.php
php cron/event-dispact.php
App - Auto Scan Listeners
-------------------------
// Auto Scan Listeners and waiting for events (daemon)
php worker-event.php
// Dispatch Events (run once)
php cron/event-dispatch_test.php
// Listen and Consume RabbitMQ
php cron/rabbitmq-receiver.php
######################################################
CRON Testing
######################################################
Consumers (daemon)
==================
php cron/event-listener.php
php cron/queue-consumer.php
php cron/rabbitmq-receiver.php
Senders (single run)
====================
php cron/event-dispatch_test.php
php cron/queue.php
php cron/rabbitmq-receiver.php
Indexing
========
php cron/meiliserach.php
php cron/indexing.php
######################################################
Framework - Performance Testing
######################################################
Using k6 - grafana
==================
mkdir -p $HOME/tmp
cp $PWD/test/k6-test.js $HOME/tmp/k6-test.js
k6 run $HOME/tmp/k6-test.js
// Debuging Run once
k6 run --vus 1 --iterations 1 $HOME/tmp/k6-test.js
RESULTS: ./test/TEST.txt
------------------------
k6 run $HOME/tmp/k6-test.js > $PWD/test/TEST.txt 2>&1
APPEND RESULTS:
---------------
k6 run $HOMEtmp/k6-test.js >> $PWD/test/TEST.txt 2>&1
SHOW OUTPUT (verbose):
----------------------
k6 run $HOME/tmp/k6-test.js | tee $PWD/test/TEST.txt
Format to JSON:
---------------
// Debuging Run once
k6 run --vus 1 --iterations 1 --summary-export=$HOME/tmp/TEST_SUMMARY.json $HOME/tmp/k6-test.js
// Debuging Run full testing
k6 run --summary-export=$HOME/tmp/TEST_SUMMARY.json $HOME/tmp/k6-test.js
// Copy TEST_SUMMARY.json to project
cp $HOME/tmp/TEST_SUMMARY.json $PWD/test/TEST_SUMMARY.json
Log BOTH
--------
k6 run --summary-export=$PWD/test/TEST_SUMMARY.json $HOME/tmp/k6-test.js > $PWD/test/TEST.txt 2>&1
Using ab tools
Apache Benchmark
-----------------
// Benchmark
ab -c 128 -n 10000 -k http://localhost:8000/health 2>&1
// POST
ab -n 1000 -c 50 \
-T application/json \
-H "X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-p $PWD/test/hey-data.json \
"http://localhost:8000/api/v1/dashboard"
Using hey tools
https://github.com/rakyll/hey
paste bin to: test/bin/
======================
test/bin/hey -n 1000 -c 50 \
-m GET \
-D $PWD/test/hey-data.json \
-H "X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
"http://localhost:8000/api/v1/dashboard"
// Output to text
test/bin/hey -n 1000 -c 50 -m GET -D $PWD/test/hey-data.json -H "X-API-KEY: zjwTis+UxjPt2VhvlqSQoTw1CZuaR0LC8a654X1ofVc=" -H "Accept: application/json" -H "Content-Type: application/json" "http://localhost:8000/api/v1/dashboard" > test/HEY_TEST.txt
test/bin/hey -n 1000 -c 50 \
-m GET \
"http://localhost:8000/testing"
######################################################
Framework - Formater
######################################################
Rector:
To see preview of suggested changed, run process command with --dry-run option:
vendor/bin/rector process --dry-run
vendor/bin/rector process --dry-run > rector.log
vendor/bin/rector process --dry-run > rector-master.log
vendor/bin/rector process --dry-run > storage/framework/cache/rector.log
vendor/bin/rector process --dry-run --debug > storage/framework/cache/rector.log
To make changes happen, run bare command:
vendor/bin/rector process
vendor/bin/rector process > rector-master.log
######################################################
######################################################
######################################################